-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (29 loc) · 963 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import constants
from repos import GitRepo
from blog_parser import BlogParser
from feed import BlogFeed
def main():
print("Updating blog repo")
blog_repo = GitRepo(force=True, **constants.BLOG_CONF)
print("Updating atom repo")
atom_repo = GitRepo(force=True, **constants.ATOM_CONF)
parser = BlogParser(blog_repo.path)
articles = parser.articles()
committed_at = blog_repo.last_committed_at
atom_path = os.path.join(atom_repo.path, "atom.xml")
atom_updated = BlogFeed.get_atom_update_time(atom_path)
if committed_at == atom_updated:
print("Atom feed is up to date, exit.")
return
print("Generating atom.xml")
feed = BlogFeed(committed_at)
feed.update(articles[:50])
feed.save(atom_path)
if atom_repo.repo.is_dirty():
print("Commit & push feed repo")
atom_repo.commit_all()
atom_repo.push()
print("Done!")
if __name__ == "__main__":
main()