Git actions and new config file format
This commit is contained in:
parent
b091d20bf3
commit
28e032e0cf
37
blogbot.py
37
blogbot.py
|
@ -58,7 +58,8 @@ def create_extract(txt):
|
|||
|
||||
def parse_feeds(weeks, username, blog):
|
||||
feedparser.USER_AGENT = "IronBloggerBot/0.2 +http://ironblogger.de/"
|
||||
uri = blog[3]
|
||||
uri = blog['feed']
|
||||
print("Retreiving ", uri)
|
||||
feed = feedparser.parse(uri)
|
||||
|
||||
if not feed.entries:
|
||||
|
@ -82,25 +83,33 @@ def parse_feeds(weeks, username, blog):
|
|||
if post['url'] not in [p['url'] for p in weeks[key]]:
|
||||
weeks[key].append(post)
|
||||
|
||||
# -- main
|
||||
|
||||
config=settings.load_settings()
|
||||
|
||||
if os.path.exists('data'):
|
||||
shutil.rmtree('data')
|
||||
|
||||
gitrepo = Repo.clone_from('https://git.wazong.de/iron-blogger/content-society.git', 'data')
|
||||
gitrepo = Repo.clone_from('https://git.wazong.de/iron-blogger/test.git', 'data')
|
||||
|
||||
with open('data/bloggers.yml') as f:
|
||||
users = yaml.safe_load(f.read())
|
||||
try:
|
||||
with open('data/blogs.yaml') as f:
|
||||
users = yaml.safe_load(f.read())
|
||||
except FileNotFoundError:
|
||||
users = []
|
||||
|
||||
print(users)
|
||||
|
||||
if not os.path.exists('data/out'):
|
||||
os.makedirs('data/out')
|
||||
try:
|
||||
with open('data/out/report.yml') as f:
|
||||
with open('data/out/report.yaml') as f:
|
||||
log = yaml.safe_load(f.read())
|
||||
except IOError:
|
||||
except FileNotFoundError:
|
||||
log = {}
|
||||
|
||||
START = datetime.datetime.strptime(config['start_date'],'%Y/%m/%d')
|
||||
# START = datetime.datetime.strptime(config['start_date'],'%Y/%m/%d')
|
||||
START = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) - datetime.timedelta(days=7)
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
for username in sys.argv[1:]:
|
||||
|
@ -114,8 +123,18 @@ else:
|
|||
if enddate < datetime.datetime.now():
|
||||
print("User inactive: ", username)
|
||||
continue
|
||||
for l in u['links']:
|
||||
for l in u['blogs']:
|
||||
parse_feeds(log, username, l)
|
||||
|
||||
with open('data/out/report.yml', 'w') as f:
|
||||
with open('data/out/report.yaml', 'w') as f:
|
||||
yaml.safe_dump(log, f)
|
||||
gitrepo.index.add(['out/report.yaml'])
|
||||
|
||||
with open('data/blogs.yaml', 'w') as f:
|
||||
yaml.safe_dump(users, f)
|
||||
gitrepo.index.add(['blogs.yaml'])
|
||||
|
||||
print(gitrepo.index.diff(gitrepo.head.commit))
|
||||
|
||||
# gitrepo.index.commit('autocommit')
|
||||
# gitrepo.remotes.origin.push()
|
|
@ -4,13 +4,14 @@ import configparser, os
|
|||
def load_settings():
|
||||
configfile = configparser.ConfigParser()
|
||||
configfile.read('settings.cfg')
|
||||
|
||||
config=dict()
|
||||
config['mail']=configfile.get("general","mail")
|
||||
config['start_date']=configfile.get("general","start_date")
|
||||
config['report_interval']=configfile.get("general","report_interval", fallback="weekly")
|
||||
|
||||
config['username']=configfile.get("blogsettings","username")
|
||||
config['password']=configfile.get("blogsettings","password")
|
||||
config['password']=configfile.get("blogsettings","password", fallback="")
|
||||
config['xmlrpc_endpoint']=configfile.get("blogsettings","xmlrpc_endpoint")
|
||||
config['blog_id']=configfile.get("blogsettings","blog_id")
|
||||
config['blog_id']=configfile.get("blogsettings","blog_id", fallback="0")
|
||||
config['participants_page_id']=configfile.get("blogsettings","participants_page_id")
|
||||
return config
|
||||
|
|
Loading…
Reference in a new issue