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):
|
def parse_feeds(weeks, username, blog):
|
||||||
feedparser.USER_AGENT = "IronBloggerBot/0.2 +http://ironblogger.de/"
|
feedparser.USER_AGENT = "IronBloggerBot/0.2 +http://ironblogger.de/"
|
||||||
uri = blog[3]
|
uri = blog['feed']
|
||||||
|
print("Retreiving ", uri)
|
||||||
feed = feedparser.parse(uri)
|
feed = feedparser.parse(uri)
|
||||||
|
|
||||||
if not feed.entries:
|
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]]:
|
if post['url'] not in [p['url'] for p in weeks[key]]:
|
||||||
weeks[key].append(post)
|
weeks[key].append(post)
|
||||||
|
|
||||||
|
# -- main
|
||||||
|
|
||||||
config=settings.load_settings()
|
config=settings.load_settings()
|
||||||
|
|
||||||
if os.path.exists('data'):
|
if os.path.exists('data'):
|
||||||
shutil.rmtree('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:
|
try:
|
||||||
users = yaml.safe_load(f.read())
|
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'):
|
if not os.path.exists('data/out'):
|
||||||
os.makedirs('data/out')
|
os.makedirs('data/out')
|
||||||
try:
|
try:
|
||||||
with open('data/out/report.yml') as f:
|
with open('data/out/report.yaml') as f:
|
||||||
log = yaml.safe_load(f.read())
|
log = yaml.safe_load(f.read())
|
||||||
except IOError:
|
except FileNotFoundError:
|
||||||
log = {}
|
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:
|
if len(sys.argv) > 1:
|
||||||
for username in sys.argv[1:]:
|
for username in sys.argv[1:]:
|
||||||
|
@ -114,8 +123,18 @@ else:
|
||||||
if enddate < datetime.datetime.now():
|
if enddate < datetime.datetime.now():
|
||||||
print("User inactive: ", username)
|
print("User inactive: ", username)
|
||||||
continue
|
continue
|
||||||
for l in u['links']:
|
for l in u['blogs']:
|
||||||
parse_feeds(log, username, l)
|
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)
|
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():
|
def load_settings():
|
||||||
configfile = configparser.ConfigParser()
|
configfile = configparser.ConfigParser()
|
||||||
configfile.read('settings.cfg')
|
configfile.read('settings.cfg')
|
||||||
|
|
||||||
config=dict()
|
config=dict()
|
||||||
config['mail']=configfile.get("general","mail")
|
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['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['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")
|
config['participants_page_id']=configfile.get("blogsettings","participants_page_id")
|
||||||
return config
|
return config
|
||||||
|
|
Loading…
Reference in New Issue