Merge branch 'python3' of iron-blogger/iron-blogger into master
Python 2 is no longer able to connect to modern https-Servers. Also it’s outdated. ;-)
This commit is contained in:
commit
6666300c93
|
@ -1,16 +1,17 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
from lxml import html
|
from lxml import html
|
||||||
import yaml
|
import yaml
|
||||||
import sys
|
import sys
|
||||||
import urllib2
|
import urllib.request
|
||||||
import urlparse
|
import urllib.parse
|
||||||
|
|
||||||
with open('bloggers.yml') as f:
|
with open('bloggers.yml') as f:
|
||||||
users = yaml.safe_load(f.read())
|
users = yaml.safe_load(f.read())
|
||||||
|
|
||||||
def fetch_links(url):
|
def fetch_links(url):
|
||||||
print >>sys.stderr, "Looking for feeds in %s" % (url,)
|
print("Looking for feeds in %s" % (url,), file=sys.stderr)
|
||||||
tree = html.fromstring(urllib2.urlopen(url).read())
|
try:
|
||||||
|
tree = html.document_fromstring(urllib.request.urlopen(url).read())
|
||||||
links = tree.xpath(
|
links = tree.xpath(
|
||||||
'//link[@rel="alternate"][contains(@type, "rss") or ' +
|
'//link[@rel="alternate"][contains(@type, "rss") or ' +
|
||||||
'contains(@type, "atom") or contains(@type, "rdf")]')
|
'contains(@type, "atom") or contains(@type, "rdf")]')
|
||||||
|
@ -18,15 +19,19 @@ def fetch_links(url):
|
||||||
'atom' in l.attrib['type'] and
|
'atom' in l.attrib['type'] and
|
||||||
'comments' not in l.attrib['href'].lower() and
|
'comments' not in l.attrib['href'].lower() and
|
||||||
'comments' not in l.attrib.get('title','')]
|
'comments' not in l.attrib.get('title','')]
|
||||||
|
except:
|
||||||
|
candidates = []
|
||||||
|
links = []
|
||||||
if candidates:
|
if candidates:
|
||||||
return candidates[0].attrib['href']
|
return candidates[0].attrib['href']
|
||||||
elif links:
|
elif links:
|
||||||
return links[0].attrib['href']
|
return links[0].attrib['href']
|
||||||
else:
|
else:
|
||||||
print >>sys.stderr, "No link found for %s" % (url,)
|
print("No link found for %s" % (url,), file=sys.stderr)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for (name, u) in users.items():
|
for (name, u) in list(users.items()):
|
||||||
|
print("Processing user %s" % (name,), file=sys.stderr)
|
||||||
for e in u['links']:
|
for e in u['links']:
|
||||||
(title, url) = e[1:3]
|
(title, url) = e[1:3]
|
||||||
try:
|
try:
|
||||||
|
@ -38,7 +43,7 @@ for (name, u) in users.items():
|
||||||
link = fetch_links(url)
|
link = fetch_links(url)
|
||||||
if link:
|
if link:
|
||||||
if not link.startswith('http:'):
|
if not link.startswith('http:'):
|
||||||
link = urlparse.urljoin(url, link)
|
link = urllib.parse.urljoin(url, link)
|
||||||
e.append(link)
|
e.append(link)
|
||||||
|
|
||||||
with open('bloggers.yml', 'w') as f:
|
with open('bloggers.yml', 'w') as f:
|
||||||
|
|
13
render.py
13
render.py
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
# This Python file uses the following encoding: utf-8
|
# This Python file uses the following encoding: utf-8
|
||||||
import yaml
|
import yaml
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
|
@ -29,6 +29,7 @@ def get_balance(acct):
|
||||||
def get_debts():
|
def get_debts():
|
||||||
p = subprocess.Popen(['ledger', '-f', os.path.join(HERE, 'ledger'),
|
p = subprocess.Popen(['ledger', '-f', os.path.join(HERE, 'ledger'),
|
||||||
'-n', 'balance', 'Pool:Owed:'],
|
'-n', 'balance', 'Pool:Owed:'],
|
||||||
|
universal_newlines=True,
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE)
|
||||||
(out, _) = p.communicate()
|
(out, _) = p.communicate()
|
||||||
debts = []
|
debts = []
|
||||||
|
@ -48,7 +49,7 @@ def parse_skip(rec):
|
||||||
out = []
|
out = []
|
||||||
for s in spec:
|
for s in spec:
|
||||||
if isinstance(s, list):
|
if isinstance(s, list):
|
||||||
out.append(map(to_week_num, s))
|
out.append(list(map(to_week_num, s)))
|
||||||
else:
|
else:
|
||||||
out.append(to_week_num(s))
|
out.append(to_week_num(s))
|
||||||
return out
|
return out
|
||||||
|
@ -72,7 +73,7 @@ def render_template(path, week=None, **kwargs):
|
||||||
else:
|
else:
|
||||||
week = START
|
week = START
|
||||||
|
|
||||||
week = (week - START).days / 7
|
week = int( (week - START).days / 7)
|
||||||
week_start = START + (week * datetime.timedelta(7))
|
week_start = START + (week * datetime.timedelta(7))
|
||||||
week_end = START + ((week + 1) * datetime.timedelta(7))
|
week_end = START + ((week + 1) * datetime.timedelta(7))
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ def render_template(path, week=None, **kwargs):
|
||||||
class User(object):
|
class User(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for (un, rec) in users.items():
|
for (un, rec) in list(users.items()):
|
||||||
u = User()
|
u = User()
|
||||||
u.username = un
|
u.username = un
|
||||||
u.name = rec['name']
|
u.name = rec['name']
|
||||||
|
@ -144,10 +145,10 @@ def render_template(path, week=None, **kwargs):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print >>sys.stderr, "Usage: %s TEMPLATE [WEEK]"
|
print("Usage: %s TEMPLATE [WEEK]", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
template = sys.argv[1]
|
template = sys.argv[1]
|
||||||
week = None
|
week = None
|
||||||
if len(sys.argv) > 2: week = sys.argv[2]
|
if len(sys.argv) > 2: week = sys.argv[2]
|
||||||
print render_template(template, week)
|
print(render_template(template, week))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
import yaml
|
import yaml
|
||||||
import feedparser
|
import feedparser
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -37,26 +37,26 @@ def get_link(post):
|
||||||
return post.link
|
return post.link
|
||||||
|
|
||||||
def parse_feeds(weeks, uri):
|
def parse_feeds(weeks, uri):
|
||||||
feedparser.USER_AGENT = "IronBloggerBot/0.1 +http://ironblogger.de/"
|
feedparser.USER_AGENT = "IronBloggerBot/0.2 +http://ironblogger.de/"
|
||||||
feed = feedparser.parse(uri)
|
feed = feedparser.parse(uri)
|
||||||
|
|
||||||
if not feed.entries:
|
if not feed.entries:
|
||||||
print >>sys.stderr, "WARN: no entries for ", uri
|
print("WARN: no entries for ", uri, file=sys.stderr)
|
||||||
for post in feed.entries:
|
for post in feed.entries:
|
||||||
date = parse_published(get_date(post))
|
date = parse_published(get_date(post))
|
||||||
|
|
||||||
if date < START:
|
if date < START:
|
||||||
continue
|
continue
|
||||||
wn = (date - START).days / 7
|
wn = int ( (date - START).days / 7 )
|
||||||
|
|
||||||
while len(weeks) <= wn:
|
while len(weeks) <= wn:
|
||||||
weeks.append([])
|
weeks.append([])
|
||||||
|
|
||||||
if post.has_key('title'):
|
if 'title' in post:
|
||||||
post = dict(date=date,
|
post = dict(date=date,
|
||||||
title=post.title,
|
title=post.title,
|
||||||
url=get_link(post))
|
url=get_link(post))
|
||||||
if not post.has_key('title'):
|
if 'title' not in post:
|
||||||
post = dict(date=date,
|
post = dict(date=date,
|
||||||
title="",
|
title="",
|
||||||
url=get_link(post))
|
url=get_link(post))
|
||||||
|
@ -70,7 +70,7 @@ if len(sys.argv) > 1:
|
||||||
weeks = blogs.setdefault(l[0], [])
|
weeks = blogs.setdefault(l[0], [])
|
||||||
parse_feeds(weeks, l[3])
|
parse_feeds(weeks, l[3])
|
||||||
else:
|
else:
|
||||||
for (username, u) in users.items():
|
for (username, u) in list(users.items()):
|
||||||
blogs = log.setdefault(username, {})
|
blogs = log.setdefault(username, {})
|
||||||
for l in u['links']:
|
for l in u['links']:
|
||||||
weeks = blogs.setdefault(l[0], [])
|
weeks = blogs.setdefault(l[0], [])
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import ConfigParser, os
|
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")
|
||||||
|
|
|
@ -53,7 +53,7 @@ Paid: € ${paid}
|
||||||
Events: € ${event}
|
Events: € ${event}
|
||||||
Individual debts:
|
Individual debts:
|
||||||
% for (u, v) in sorted(debts, key=lambda p:p[1], reverse=True):
|
% for (u, v) in sorted(debts, key=lambda p:p[1], reverse=True):
|
||||||
${u"%20s %d \u20AC" % (u, v)}
|
${"%20s %d \u20AC" % (u, v)}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
PREVIOUSLY PUNTED (pay € 30 balance to return):
|
PREVIOUSLY PUNTED (pay € 30 balance to return):
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import render
|
import render
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import xmlrpclib
|
import xmlrpc.client
|
||||||
import subprocess
|
import subprocess
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
config=settings.load_settings()
|
config=settings.load_settings()
|
||||||
|
|
||||||
x = xmlrpclib.ServerProxy(config['xmlrpc_endpoint'])
|
x = xmlrpc.client.ServerProxy(config['xmlrpc_endpoint'])
|
||||||
page = x.wp.getPage(config['blog_id'], config['participants_page_id'], config['username'], config['password'])
|
page = x.wp.getPage(config['blog_id'], config['participants_page_id'], config['username'], config['password'])
|
||||||
|
|
||||||
text = render.render_template('templates/users.tmpl')
|
text = render.render_template('templates/users.tmpl')
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
# This Python file uses the following encoding: utf-8
|
# This Python file uses the following encoding: utf-8
|
||||||
import render
|
import render
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import xmlrpclib
|
import xmlrpc.client
|
||||||
import subprocess
|
import subprocess
|
||||||
import datetime
|
import datetime
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -39,7 +39,8 @@ date = args[0]
|
||||||
|
|
||||||
with open('ledger', 'a') as f:
|
with open('ledger', 'a') as f:
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
f.write(render.render_template('templates/ledger', date))
|
# print(render.render_template('templates/ledger', date).decode("utf-8"))
|
||||||
|
f.write(render.render_template('templates/ledger', date).decode("utf-8"))
|
||||||
|
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
subprocess.check_call(["git", "commit", "ledger",
|
subprocess.check_call(["git", "commit", "ledger",
|
||||||
|
@ -61,7 +62,7 @@ with open('ledger', 'a') as f:
|
||||||
|
|
||||||
|
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
text = render.render_template('templates/week.tmpl', date, punt=punt)
|
text = render.render_template('templates/week.tmpl', date, punt=punt).decode("utf-8")
|
||||||
|
|
||||||
lines = text.split("\n")
|
lines = text.split("\n")
|
||||||
title = lines[0]
|
title = lines[0]
|
||||||
|
@ -69,16 +70,16 @@ if not dry_run:
|
||||||
|
|
||||||
page = dict(title = title, description = body)
|
page = dict(title = title, description = body)
|
||||||
|
|
||||||
x = xmlrpclib.ServerProxy(config['xmlrpc_endpoint'])
|
x = xmlrpc.client.ServerProxy(config['xmlrpc_endpoint'])
|
||||||
x.metaWeblog.newPost(config['blog_id'], config['username'], config['password'], page, True)
|
x.metaWeblog.newPost(config['blog_id'], config['username'], config['password'], page, True)
|
||||||
if not reminder:
|
if not reminder:
|
||||||
email = render.render_template('templates/email.txt', date, punt=punt,mail=config['mail'])
|
email = render.render_template('templates/email.txt', date, punt=punt,mail=config['mail'])
|
||||||
else:
|
else:
|
||||||
email = render.render_template('templates/reminder.txt', date, punt=punt,mail=config['mail'])
|
email = render.render_template('templates/reminder.txt', date, punt=punt,mail=config['mail'])
|
||||||
if quick_view:
|
if quick_view:
|
||||||
print(render.render_template('templates/quick_view.tmpl',date,punt=punt))
|
print((render.render_template('templates/quick_view.tmpl',date,punt=punt)))
|
||||||
if dry_run and not quick_view:
|
if dry_run and not quick_view:
|
||||||
print email
|
print(email)
|
||||||
if send_mail:
|
if send_mail:
|
||||||
# p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
|
# p = subprocess.Popen(['mutt', '-H', '/dev/stdin'],
|
||||||
p = subprocess.Popen(['/usr/sbin/sendmail', '-oi', '-t'],
|
p = subprocess.Popen(['/usr/sbin/sendmail', '-oi', '-t'],
|
||||||
|
|
Loading…
Reference in a new issue