Created
October 16, 2020 18:33
-
-
Save offlinehacker/13fcbfc2cb862a8b2e40771030ea00bc to your computer and use it in GitHub Desktop.
csv2pocket - tool to import csv to pocket
This file contains hidden or 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
import csv | |
import argparse | |
import sys | |
import requests | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--csv", help="CSV to import", required=True) | |
parser.add_argument("--encoding", help="File encoding", default="utf-8") | |
parser.add_argument("--token", help="API token to use", required=True) | |
parser.add_argument("--consumerkey", help="Consumer key token to use", required=True) | |
parser.add_argument("--title", help="Title column", required=True) | |
parser.add_argument("--tags", help="Tags column", required=False) | |
parser.add_argument("--url", help="URL column", required=False) | |
args = parser.parse_args() | |
links=[] | |
with open(args.csv, newline='', encoding=args.encoding) as csvfile: | |
reader = csv.DictReader(csvfile) | |
for row in reader: | |
if args.title not in row: | |
print("missing title column in row: {}".format(row)) | |
sys.exit(1) | |
title=row[args.title] | |
if args.url not in row: | |
print("missing url column in row: {}".format(row)) | |
sys.exit(1) | |
url=row[args.url] | |
tags="" | |
if args.tags and args.tags not in row: | |
print("missing tags column in row: {}".format(row)) | |
sys.exit(1) | |
elif args.tags: | |
tags=row[args.tags] | |
data={ | |
'title': title, | |
'url': url, | |
'tags': tags, | |
'consumer_key': args.consumerkey, | |
'access_token': args.token | |
} | |
print("posting data: ", data) | |
res = requests.post("https://getpocket.com/v3/add", data=data) | |
if res.status_code != 200: | |
print("invalid response code {}, error: {}".format(res.status_code, res.content)) | |
sys.exit(1) |
This file contains hidden or 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
#!/usr/bin/env python | |
import pocket | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--consumerkey", help="Consumer key token to use", required=True) | |
args = parser.parse_args() | |
request_token = pocket.Pocket.get_request_token( | |
consumer_key=args.consumerkey, | |
redirect_uri="http://localhost:8080/") | |
auth_url = pocket.Pocket.get_auth_url( | |
code=request_token, | |
redirect_uri="http://localhost:8080/") | |
print("Go to %s and press enter" % auth_url) | |
input() | |
user_credentials = pocket.Pocket.get_credentials( | |
consumer_key=args.consumerkey, | |
code=request_token) | |
access_token = user_credentials['access_token'] | |
print("Access granted! Your token is: %s" % access_token) |
This file contains hidden or 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
{ nixpkgs ? import <nixpkgs> {} }: | |
with nixpkgs; | |
stdenv.mkDerivation rec { | |
name = "python-virtualenv-shell"; | |
env = buildEnv { name = name; paths = buildInputs; }; | |
buildInputs = [ | |
(python37.withPackages (pypkgs: with pypkgs; [ requests pocket ])) | |
pipenv | |
]; | |
shellHook = '' | |
# set SOURCE_DATE_EPOCH so that we can use python wheels | |
SOURCE_DATE_EPOCH=$(date +%s) | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment