Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
Boop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Marien Fressinaud
Boop
Commits
c9eff5a1
Commit
c9eff5a1
authored
Dec 12, 2018
by
Marien Fressinaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tec: Abstract the feed generation with Boopfeed
parent
43428c21
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
34 deletions
+80
-34
boop.py
boop.py
+26
-34
boopfeed.py
boopfeed.py
+54
-0
No files found.
boop.py
View file @
c9eff5a1
...
...
@@ -12,9 +12,8 @@ import uuid
import
markdown
import
pytz
import
xml.etree.ElementTree
as
ET
import
boopsy
import
boopfeed
locale
.
setlocale
(
locale
.
LC_ALL
,
""
)
...
...
@@ -196,10 +195,6 @@ def main():
with
open
(
output_filepath
,
"w"
)
as
output_file
:
output_file
.
write
(
article
.
render
())
# Finish by writing the news feed
feed_dirpath
=
os
.
path
.
join
(
output_path
,
"feeds"
)
os
.
mkdir
(
feed_dirpath
)
# Just create some variables so it's easier to manipulate after
site_url
=
configuration
[
"SITE_URL"
]
site_uuid
=
configuration
[
"SITE_UUID"
]
...
...
@@ -208,45 +203,42 @@ def main():
timezone
=
pytz
.
timezone
(
site_timezone
)
current_datetime
=
datetime
.
datetime
.
now
(
tz
=
timezone
)
# Start to build the XML feed with the root information
feed
=
ET
.
Element
(
"feed"
,
xmlns
=
"http://www.w3.org/2005/Atom"
)
ET
.
SubElement
(
feed
,
"title"
)
.
text
=
site_title
ET
.
SubElement
(
feed
,
"link"
,
href
=
f
"{site_url}feeds/all.atom.xml"
,
rel
=
"self"
,
type
=
"application/atom+xml"
,
# Build the Atom feed
feed
=
boopfeed
.
Atom
()
feed
.
add_header
(
{
"title"
:
site_title
,
"self_link"
:
f
"{site_url}feeds/all.atom.xml"
,
"site_link"
:
site_url
,
"id"
:
f
"urn:uuid:{site_uuid}"
,
"updated"
:
current_datetime
,
}
)
ET
.
SubElement
(
feed
,
"link"
,
href
=
site_url
,
rel
=
"alternate"
,
type
=
"text/html"
)
ET
.
SubElement
(
feed
,
"id"
)
.
text
=
f
"urn:uuid:{site_uuid}"
ET
.
SubElement
(
feed
,
"updated"
)
.
text
=
current_datetime
.
isoformat
(
timespec
=
"seconds"
)
for
article
in
articles
:
# and complete it for each article
entry
=
ET
.
SubElement
(
feed
,
"entry"
)
ET
.
SubElement
(
entry
,
"title"
)
.
text
=
article
.
title
()
ET
.
SubElement
(
entry
,
"id"
)
.
text
=
f
"urn:uuid:{article.uuid()}"
entry
=
{
"title"
:
article
.
title
(),
"id"
:
f
"urn:uuid:{article.uuid()}"
,
"article_link"
:
article
.
url
(),
"published"
:
article
.
date
(),
"content"
:
article
.
content
(),
}
article_author
=
article
.
author
()
if
article_author
:
author
=
ET
.
SubElement
(
entry
,
"author"
)
ET
.
SubElement
(
author
,
"name"
)
.
text
=
article_author
ET
.
SubElement
(
entry
,
"link"
,
href
=
article
.
url
(),
rel
=
"alternate"
,
type
=
"text/html"
)
ET
.
SubElement
(
entry
,
"published"
)
.
text
=
article
.
date
()
.
isoformat
(
timespec
=
"seconds"
)
entry
[
"author"
]
=
article_author
article_update
=
article
.
update
()
if
article_update
:
ET
.
SubElement
(
entry
,
"updated"
)
.
text
=
article_update
.
isoformat
(
timespec
=
"seconds"
)
ET
.
SubElement
(
entry
,
"content"
,
type
=
"html"
)
.
text
=
article
.
content
()
entry
[
"updated"
]
=
article_update
feed
.
add_entry
(
entry
)
# And write it on the filesystem
feed_dirpath
=
os
.
path
.
join
(
output_path
,
"feeds"
)
os
.
mkdir
(
feed_dirpath
)
feed_filepath
=
os
.
path
.
join
(
feed_dirpath
,
"all.atom.xml"
)
ET
.
ElementTree
(
feed
)
.
write
(
feed_filepath
,
encoding
=
"unicode"
,
xml_declaration
=
True
)
feed
.
write
(
feed_filepath
)
if
__name__
==
"__main__"
:
...
...
boopfeed.py
0 → 100644
View file @
c9eff5a1
import
xml.etree.ElementTree
as
ET
class
Atom
:
def
__init__
(
self
):
self
.
feed
=
ET
.
Element
(
"feed"
,
xmlns
=
"http://www.w3.org/2005/Atom"
)
def
add_header
(
self
,
attributes
):
ET
.
SubElement
(
self
.
feed
,
"title"
)
.
text
=
attributes
[
"title"
]
ET
.
SubElement
(
self
.
feed
,
"link"
,
href
=
attributes
[
"self_link"
],
rel
=
"self"
,
type
=
"application/atom+xml"
,
)
ET
.
SubElement
(
self
.
feed
,
"link"
,
href
=
attributes
[
"site_link"
],
rel
=
"alternate"
,
type
=
"text/html"
,
)
ET
.
SubElement
(
self
.
feed
,
"id"
)
.
text
=
attributes
[
"id"
]
ET
.
SubElement
(
self
.
feed
,
"updated"
)
.
text
=
attributes
[
"updated"
]
.
isoformat
(
timespec
=
"seconds"
)
def
add_entry
(
self
,
attributes
):
entry
=
ET
.
SubElement
(
self
.
feed
,
"entry"
)
ET
.
SubElement
(
entry
,
"title"
)
.
text
=
attributes
[
"title"
]
ET
.
SubElement
(
entry
,
"id"
)
.
text
=
attributes
[
"id"
]
if
"author"
in
attributes
:
author
=
ET
.
SubElement
(
entry
,
"author"
)
ET
.
SubElement
(
author
,
"name"
)
.
text
=
attributes
[
"author"
]
ET
.
SubElement
(
entry
,
"link"
,
href
=
attributes
[
"article_link"
],
rel
=
"alternate"
,
type
=
"text/html"
,
)
ET
.
SubElement
(
entry
,
"published"
)
.
text
=
attributes
[
"published"
]
.
isoformat
(
timespec
=
"seconds"
)
if
"updated"
in
attributes
:
ET
.
SubElement
(
entry
,
"updated"
)
.
text
=
attributes
[
"updated"
]
.
isoformat
(
timespec
=
"seconds"
)
ET
.
SubElement
(
entry
,
"content"
,
type
=
"html"
)
.
text
=
attributes
[
"content"
]
def
write
(
self
,
filepath
):
element_tree
=
ET
.
ElementTree
(
self
.
feed
)
element_tree
.
write
(
filepath
,
encoding
=
"unicode"
,
xml_declaration
=
True
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment