-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetch_timeline.py
35 lines (30 loc) · 952 Bytes
/
fetch_timeline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys
from plistlib import load
import requests
import json
import re
# Authentication
info = load(open('info.plist','rb'))
access = info['variables']['access_key']
instance = info['variables']['instance']
head = {'Authorization':'Bearer '+access}
param = {'limit':50}
timelines = json.loads(requests.get(instance+'/api/v1/timelines/home',headers=head,params=param).content.decode('utf-8'))
def strip(t):
t = re.sub('</p><p>','\n',t)
t = re.sub('(<.?p>|<.?a.*?>|<.?span.*?>)','',t)
t = re.sub('<','<',t)
t = re.sub('>','>',t)
t = re.sub(''','\'',t)
t = re.sub('"','\'',t)
t = re.sub('<br.*?\/?>','\n',t)
return t
items = list()
for timeline in timelines:
item = dict()
item["title"] = strip(timeline['content'])
item["subtitle"] = "from: "+str(timeline['account']['acct'])
item["arg"] = timeline['id']
items.append(item)
results = {"items":items}
print(json.dumps(results))