Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Quick script to publish my Trakt history to my website
from import UTC
from dateutil.parser import parse
from datetime import datetime
import conf
import json
import os
import feedparser
import requests
def make_id(seed):
return seed.replace('/', '-').replace(':', '-').replace(',', '-')
feed = feedparser.parse(conf.FEED_URL)
now = datetime.utcnow().astimezone(UTC)
for entry in feed['items']:
data = {
'title': entry['title'],
'summary': entry['summary'],
'link': entry['link']
if len(data['summary']) == 0:
data['summary'] = entry['title']
when = parse(entry['published'])
poster_url = entry['media_content'][0]['url']
if 'Episode' in entry['id']:
data['type'] = 'tv'
elif 'Movie' in entry['id']:
data['type'] = 'movie'
media_id = make_id(entry['id'])
footprint = conf.HISTORY_PATH + '/' + media_id
if os.path.exists(footprint):
print('Skipping ->', media_id, '->', data['title'])
print('Publishing ->', media_id, '->', data['title'])
poster_response = requests.get(poster_url)
response ='', data={
'payload': json.dumps(data)
}, files={
'photo': (
poster_url.rsplit('/', 1)[1],
{'Expires': '0'}
if response.status_code in (200, 201, 202):
open(footprint, 'w').write(json.dumps(data))
print('Successfully published ->', media_id)
print('Failed to publish ->', media_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment