Skip to content

Commit

Permalink
Add .gitignore file
Browse files Browse the repository at this point in the history
  • Loading branch information
Canorus committed Feb 26, 2019
1 parent 25d644b commit 24573f3
Show file tree
Hide file tree
Showing 13 changed files with 1,190 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
info.plist
Binary file added D09F5FBF-A1FE-456A-834C-3B1835A36B58.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions access_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
from plistlib import readPlist, writePlist
import requests
import json

code = os.getenv('key_code')
client_id = os.getenv('client_id')
client_secret = os.getenv('client_secret')
instance = os.getenv('instance')
auth_data = {'client_id':client_id,'client_secret':client_secret,'code':code,'grant_type':'authorization_code','redirect_uri':'urn:ietf:wg:oauth:2.0:oob'}
rauth = requests.post(instance+'/oauth/token',data=auth_data)
access = rauth.json()['access_token']
info = readPlist('info.plist')
info['variables']['access_key'] = access
writePlist(info, 'info.plist')
30 changes: 30 additions & 0 deletions app_reg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import requests
import sys
from plistlib import readPlist, writePlist
import webbrowser

address = sys.argv[1]
if address[0:8] != 'https://':
address = 'https://'+address

#put instance address to environmental variables
info = readPlist('info.plist')
info['variables']['instance'] = address
writePlist(info, 'info.plist')

client_name = 'Alfred'
data = {'client_name':client_name,'redirect_uris':'urn:ietf:wg:oauth:2.0:oob','scopes':'read write'}
r = requests.post(address+'/api/v1/apps',data=data)

if r.status_code != 200:
print('error')
else:
rdata = r.json()
client_id = rdata['client_id']
client_secret = rdata['client_secret']
# saving credentials to environmental variables
info['variables']['client_id'] = client_id
info['variables']['client_secret'] = client_secret
writePlist(info, 'info.plist')
#open authentication page
webbrowser.open(address+'/oauth/authorize?client_id='+client_id+'&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=read%20write')
14 changes: 14 additions & 0 deletions boost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import requests
import sys
from plistlib import load

toot = sys.argv[1] # toot id
info = load(open('info.plist','rb'))
instance = info['variables']['instance']
access = info['variables']['access_key']
status_h = {'Authorization':'Bearer '+access}

#print(access)

st = requests.post(instance+'/api/v1/statuses/'+toot+'/reblog',headers=status_h)
print(st.json())
Binary file added browser.scpt
Binary file not shown.
7 changes: 7 additions & 0 deletions code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys
from plistlib import readPlist, writePlist

code = sys.argv[1]
info = readPlist('info.plist')
info['variables']['key_code'] = code
writePlist(info,'info.plist')
14 changes: 14 additions & 0 deletions fav.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import requests
import sys
from plistlib import load

toot = sys.argv[1] # toot id
info = load(open('info.plist','rb'))
instance = info['variables']['instance']
access = info['variables']['access_key']
status_h = {'Authorization':'Bearer '+access}

#print(access)

st = requests.post(instance+'/api/v1/statuses/'+toot+'/favourite',headers=status_h)
print(st.json())
35 changes: 35 additions & 0 deletions fetch_timeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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('&lt;','<',t)
t = re.sub('&gt;','>',t)
t = re.sub('&apos;','\'',t)
t = re.sub('&quot;','\'',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))
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 24573f3

Please sign in to comment.