|
|
@ -1,11 +1,20 @@ |
|
|
|
from __future__ import print_function |
|
|
|
from argparse import ArgumentParser |
|
|
|
import sys, json, re, os, urlparse |
|
|
|
import sys, json, re, os |
|
|
|
from datetime import datetime |
|
|
|
from urllib import urlencode |
|
|
|
from urllib2 import HTTPError |
|
|
|
|
|
|
|
try: |
|
|
|
# python2 |
|
|
|
from urllib2 import urlopen, URLError, HTTPError |
|
|
|
from urllib import urlencode |
|
|
|
from urlparse import urlparse, urlunparse |
|
|
|
except ImportError: |
|
|
|
# python3 |
|
|
|
from urllib.parse import urlparse, urlunparse, urlencode, quote |
|
|
|
from urllib.request import urlopen, URLError, HTTPError |
|
|
|
|
|
|
|
from jinja2 import FileSystemLoader, Environment |
|
|
|
from common import * |
|
|
|
from etherdump.commands.common import * |
|
|
|
from time import sleep |
|
|
|
import dateutil.parser |
|
|
|
|
|
|
@ -44,9 +53,9 @@ def absurl (url, base=None): |
|
|
|
return url |
|
|
|
|
|
|
|
def url_base (url): |
|
|
|
(scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url) |
|
|
|
(scheme, netloc, path, params, query, fragment) = urlparse(url) |
|
|
|
path, _ = os.path.split(path.lstrip("/")) |
|
|
|
ret = urlparse.urlunparse((scheme, netloc, path, None, None, None)) |
|
|
|
ret = urlunparse((scheme, netloc, path, None, None, None)) |
|
|
|
if ret: |
|
|
|
ret += "/" |
|
|
|
return ret |
|
|
@ -116,14 +125,14 @@ def main (args): |
|
|
|
|
|
|
|
pads = map(loadmeta, inputs) |
|
|
|
pads = map(fixdates, pads) |
|
|
|
args.pads = pads |
|
|
|
args.pads = list(pads) |
|
|
|
|
|
|
|
if args.timestamp == None: |
|
|
|
args.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
|
|
|
|
|
|
padurlbase = re.sub(r"api/1.2.9/$", "p/", info["apiurl"]) |
|
|
|
if type(padurlbase) == unicode: |
|
|
|
padurlbase = padurlbase.encode("utf-8") |
|
|
|
# if type(padurlbase) == unicode: |
|
|
|
# padurlbase = padurlbase.encode("utf-8") |
|
|
|
args.siteurl = args.siteurl or padurlbase |
|
|
|
args.utcnow = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S +0000") |
|
|
|
|
|
|
@ -150,14 +159,15 @@ def main (args): |
|
|
|
linkbase = args.linkbase or url_base(args.feedurl) |
|
|
|
# print ("linkbase", linkbase, args.linkbase, args.feedurl) |
|
|
|
|
|
|
|
for p in pads: |
|
|
|
for p in args.pads: |
|
|
|
print ("p", p, file=sys.stderr) |
|
|
|
versions_by_type = {} |
|
|
|
p["versions_by_type"] = versions_by_type |
|
|
|
for v in p["versions"]: |
|
|
|
t = v["type"] |
|
|
|
versions_by_type[t] = v |
|
|
|
with open (versions_by_type["text"]["path"]) as f: |
|
|
|
p["text"] = f.read().decode("utf-8") |
|
|
|
p["text"] = f.read() |
|
|
|
|
|
|
|
# ADD IN LINK |
|
|
|
for v in linkversions: |
|
|
@ -171,6 +181,6 @@ def main (args): |
|
|
|
|
|
|
|
if args.output: |
|
|
|
with open(args.output, "w") as f: |
|
|
|
print (template.render(vars(args)).encode("utf-8"), file=f) |
|
|
|
print (template.render(vars(args)), file=f) |
|
|
|
else: |
|
|
|
print (template.render(vars(args)).encode("utf-8")) |
|
|
|
print (template.render(vars(args))) |
|
|
|