Leaving Facebook, welcome back!
Auf Wiedersehen, Facebook. Keinen Bock mehr auf die Datenkrake, daher nun hier.
- “Run your own infrastructure” - siehe auch media.ccc.de/v/gpn16-7582-run_your_own_fucking_infrastructure
- gebaut mit gohugo.io nachdem die Versuche mit jekyllrb.com nicht wirklich erfolgreich waren
- Download via Facebook Graph-API und Konvertierung in markdown via python:
def convertpage( content ):
# download
payload = ''
try:
payload = json.loads(content)
except:
print "JSON decoding failed!"
if 'data' in payload:
for post in payload['data']:
# make timestamp pretty
outdir = 'content/posts/' + re.sub(r'T.*$', '-' + slug(post).lower().replace(' ', '-'), post['created_time'])
if not os.path.isdir(outdir):
os.mkdir(outdir)
outfile = codecs.open(outdir + "/index.md", 'wb', "utf-8")
outfile.write("---\n")
title_link = ""
if 'message' in post:
title = post['message'].replace('\n', ' ').replace('"', '\'')
if title.startswith("http"):
outfile.write('title: "' + re.sub('http[s]?://', '', title).replace(':', '') + '"\n')
title_link = title
else:
title = re.sub('http.*$', '', title, re.UNICODE)
title = title.replace(':', '')
split = re.split("\W", title, 100, re.UNICODE)
if split.__len__() > 10:
outfile.write('title: "' + (' '.join(split[:10])) + '..."\n')
else:
outfile.write('title: "' + title + '"\n')
elif 'link' in post:
outfile.write('title: "' + post['link'] + '"\n')
if title_link == '':
title_link = post['link']
if 'from' in post and 'name' in post['from'] and post['from']['name'] != 'Wolfgang Jung':
outfile.write('author: "' + post['from']['name'].replace('*', '') + '"\n')
outfile.write("date: " + (re.sub('\+0000', '+00:00', post['created_time'])) + "\n")
outfile.write("---\n")
if 'message' in post:
outfile.write(post['message'] + "\n\n")
if 'link' in post and 'full_picture' not in post:
outfile.write('[' + re.sub('\?.*', '', post['link'].replace('_', '\\_')) + '](' + post['link'] + ')\n')
if 'full_picture' in post:
parsed = urlparse.urlparse(post['full_picture'])
if post['full_picture'].__contains__("safe_image.php"):
if 'link' in post:
outfile.write('[' + re.sub('\?.*', '', post['link'].replace('_', '\\_')) + '](' + post['link'] + ')\n')
target_image = urlparse.parse_qs(parsed.query)['url'][0]
outfile.write('\n<a href="' + post['link'] + '" target="_blank" rel="noopener"><img src="' + target_image + '" width="400" /></a>')
else:
imgname = re.sub(".*/", "", parsed.path)
shutil.copyfile('raw_img/' + imgname, outdir + '/' + imgname)
imgname = re.sub("(.png)|(.jpg)", "", imgname)
if title_link != '':
outfile.write('<a href="' + title_link + '" target="_blank" rel="noopener">{\{< gallery >}}</a>\n')
else:
outfile.write('{\{< gallery >}}\n')
outfile.close()
...
token = '.....'
response = urllib2.urlopen("https://graph.facebook.com/me/feed?fields=from,message,created_time,link,source,full_picture&limit=1000&access_token=%s" % (token))
content = response.read()
Die Bildergallerien mit HiRes Bildern für Retina werden mit dem folgenden shortcode erzeugt:
{{ $top := . }}
{{ range $idx, $original := .Page.Resources.ByType "image" }}
{{ $top.Scratch.Set "image" ($original.Fit "400x600") }}
{{ $image := $top.Scratch.Get "image" }}
{{ $top.Scratch.Set "image2" ($original.Fit "800x1200") }}
{{ $image2 := $top.Scratch.Get "image2" }}
<figure style="width: {{ add $image.Width 10 }}px; padding: 3px; background-color: #cccc">
<img src="{{ $image.RelPermalink }}" alt="Galerie Bild {{ add $idx 1}} zu {{ $top.Page.Params.Title }}" srcset="{{ $image.RelPermalink }} 1x, {{ $image2.RelPermalink }} 2x" width="{{ $image.Width }}" height="{{ $image.Height }}">
</figure>
{{ end }}
Jeder Post muss dabei in einem eigenem Verzeichnis liegen.