-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstapaper
executable file
·55 lines (47 loc) · 1.62 KB
/
instapaper
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# This file is taken from
# https://raw.githubusercontent.com/shawjia/Instapaper-cli/master/instapaper.py
# There was no license.
import requests
import sys
from config import instapaper_user, instapaper_pass
class Instapaper(object):
def __init__(self, username, password):
self.username = str(username)
self.password = str(password)
self.auth_url = 'https://www.instapaper.com/api/authenticate'
self.add_url = 'https://www.instapaper.com/api/add'
def check_login(self):
r = requests.get(self.auth_url, auth=(self.username, self.password))
if r.status_code == 200:
return True
elif r.status_code == 403:
print('403: wrong username/password')
else:
print('500: internal error')
return False
def add(self, url):
url = self.add_url + '?url=' + url
r = requests.get(url, auth=(self.username, self.password))
if r.status_code == 201:
title = r.headers['X-Instapaper-Title'];
print("[%s] added!" % title)
return True
elif r.status_code == 400:
print('400: bad reques, url needed')
elif r.status_code == 403:
print('403: wrong username/password')
else:
print(r.status_code, ': internal error')
return False
def main():
if len(sys.argv) < 2:
print('url needed')
return False
else:
url = sys.argv[1]
ins = Instapaper(instapaper_user, instapaper_pass)
return ins.add(url)
if __name__ == '__main__':
exit(not main())