def get_json( oauth_id: str, oauth_secret: str, oauth_token: str, oauth_token_secret: str, ) -> Json: LIMIT = 500 # default limit is something stupid # TODO need merging logic in DAL api = instapaper.Instapaper(oauth_id, oauth_secret) api.login_with_token(oauth_token, oauth_token_secret) user_folders = api.folders() folders: List[str] = [ 'unread', 'archive', 'starred', # default, as per api docs *(str(f['folder_id']) for f in user_folders), ] bookmarks = {} for f in folders: fbookmarks = api.bookmarks_raw(folder=f, limit=LIMIT, have=None) bookmarks[f] = fbookmarks return { 'folders': user_folders, 'bookmarks': bookmarks, }
def establish_instapaper_session(): """ Establishes an authenticated session with an Instapaper account. :return: properly authenticated Instapaper session """ instapaper_session_ = instapaper.Instapaper( config['production']['instapaper']['token'], config['production']['instapaper']['token_secret']) instapaper_session_.login(config['production']['instapaper']['username'], config['production']['instapaper']['password']) return instapaper_session_
def login(): print( "NOTE: You'll need your username/password once in order to get oauth_token" ) oauth_id = input('Your ouath_id: ') oauth_secret = input('Your ouath_secret: ') username = input('Your username: '******'Your password: ') api = instapaper.Instapaper(oauth_id, oauth_secret) odata = api.login(username, password) print("Now paste this into your secrets file") print(odata)
def send_instapaper(url=None, content=None, title=None, description=None, instapaper_user='******') -> None: params = { 'url': url, 'content': content, 'title': title, 'description': description } try: API_secret = get_keychain_pass(API_key, 'instapaper.com') I = instapaper.Instapaper(API_key, API_secret) instapaper_pass = get_keychain_pass(instapaper_user, 'instapaper.com') I.login(instapaper_user, instapaper_pass) b = instapaper.Bookmark(I, params) b.save() logging.info('Article: ' + title + ' saved to Instapaper') except Exception as e: logging.exception('Error sending article to Instapaper') raise
def get_folder_id(folder_name, instapaper_user='******') -> None: logging.info('instapaper_user = '******'instapaper.com') I = instapaper.Instapaper(API_key, API_secret) instapaper_pass = get_keychain_pass(instapaper_user, 'instapaper.com') I.login(instapaper_user, instapaper_pass) folders = I.folders() for f in folders: if folder_name in f['title']: print(f['title']) print(f['folder_id']) return f['folder_id'] except Exception as e: logging.exception('Error retrieving Instapaper folders') raise
def get_folders(instapaper_user='******') -> None: logging.info('instapaper_user = '******'instapaper.com') I = instapaper.Instapaper(API_key, API_secret) instapaper_pass = get_keychain_pass(instapaper_user, 'instapaper.com') I.login(instapaper_user, instapaper_pass) folders = I.folders() for f in folders: # print(f) # for k, v in f.items(): # print(k, v) print(f['folder_id'], '\t', f['title']) except Exception as e: logging.exception('Error retrieving Instapaper folders') raise
def get_instapaper(folder="unread", limit=10, text=True, instapaper_user='******') -> None: logging.info('instapaper_user = '******'instapaper.com') I = instapaper.Instapaper(API_key, API_secret) instapaper_pass = get_keychain_pass(instapaper_user, 'instapaper.com') I.login(instapaper_user, instapaper_pass) marks = I.bookmarks(folder, limit) for m in marks: logging.info('Article: ' + m.title) print(m.title) if text: process_article(m.title, None, m.text) else: process_article(m.title, m.html, None) except Exception as e: logging.exception('Error retrieving Instapaper articles') raise
def test_bookmarks(): instapaper_engine = instapaper.Instapaper(*app_credentials_from_netrc()) instapaper_engine.login(*credentials_from_netrc()) bookmarks = instapaper_engine.bookmarks() assert bookmarks is not None
def test_user(): instapaper_engine = instapaper.Instapaper(*app_credentials_from_netrc()) instapaper_engine.login(*credentials_from_netrc()) user = instapaper_engine.user() assert user is not None
def test_login(): instapaper_engine = instapaper.Instapaper(*app_credentials_from_netrc()) instapaper_engine.login(*credentials_from_netrc()) assert instapaper_engine.http is not None
level=logging.DEBUG, format=FORMAT, datefmt='%a, %d %b %Y %H:%M:%S', ) logging.info('--- cr2instapaper.py logging started ---.') args = getArgs() instapaper_user = args.user title = args.title content = args.content url = args.url[1:-1] # strip first and last ie quotes from url quoted form logging.info(url) logging.info(title) try: API_secret = get_keychain_pass(API_key, 'instapaper.com') I = instapaper.Instapaper(API_key, API_secret) instapaper_pass = get_keychain_pass(instapaper_user, 'instapaper.com') I.login(instapaper_user, instapaper_pass) if content is None: filename = args.file with open(filename, 'r') as article: content = article.read() if content is None: logging.info( "Processing with empty content. Which is not the point. But..") content = '' b = instapaper.Bookmark(I, { 'title': title, 'url': url,
from flask import Flask,render_template,request,redirect,url_for from flask_bootstrap import Bootstrap import instapaper I = instapaper.Instapaper("d3e10f3296b84857aff6ce62c84d7ec1", "bc408b9151394b498b997e0bc4675b02") I.login("*****@*****.**", "greedisgood1") # b = instapaper.Bookmark(I, {"url": "http://su600.cn"}) # b.save() # # 读取10条记录 # c = I.bookmarks(limit=10) # for a in c: # print(a.title) # print(a.url) # # 存档最新一条 # d = I.bookmarks(limit=1) # s=d[0].bookmark_id # print(s) # d = instapaper.Bookmark(I, {'bookmark_id': s}) # d.archive() # # 如何区分不同标签的删除按钮 submit todo app = Flask(__name__) @app.route("/",methods=['GET', 'POST']) def home(): ## 打开和刷新列表 # c = I.bookmarks(limit=10) if request.method=="GET": # print("sssssssssssssssssss")
import instapaper I = instapaper.Instapaper("<oauth_consumer_key>", "<oauth_consumer_secret>") I.login("<user_name>", "<password>") b = instapaper.Bookmark(I, {"url": "https://www.biblegateway.com/passage/?search=John+1&version=NIV"}) b.save()