-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
info.plist |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('<','<',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)) |
Oops, something went wrong.