Browse Source

Implement best practices

- capitialize variables
- reorder imports
- add comments (this was just to get the pyflakes bit to shutup)
master
jowj 3 years ago
parent
commit
bc9e36d571
  1. 35
      pinboard.py

35
pinboard.py

@ -1,21 +1,27 @@
import json
import os
import requests
import time
import requests
pinboard_token = os.environ.get("PINBOARD_TOKEN")
pinboard_base_url = "https://api.pinboard.in/v1/"
pinboard_auth_snippet = f"?auth_token={pinboard_token}"
PINBOARD_TOKEN = os.environ.get("PINBOARD_TOKEN")
PINBOARD_BASE_URL = "https://api.pinboard.in/v1/"
PINBOARD_AUTH_SNIPPET = f"?auth_token={PINBOARD_TOKEN}"
def get_all_posts():
get_post_snippet = f"posts/all?auth_token={pinboard_token}"
pinboard_url = pinboard_base_url + get_post_snippet
"""
returns a list of all pins in pinboard account
"""
get_post_snippet = f"posts/all?auth_token={PINBOARD_TOKEN}"
pinboard_url = PINBOARD_BASE_URL + get_post_snippet
return requests.get(pinboard_url)
def add_pin_url(reddit_dict):
"""
adds a pin to pinboard and returns the response
"""
add_post_snippet = "posts/add"
# headers = {'Content-type': 'application/json'}
args = {
@ -26,7 +32,7 @@ def add_pin_url(reddit_dict):
'replace': 'no'
}
post_url = pinboard_base_url + add_post_snippet + pinboard_auth_snippet
post_url = PINBOARD_BASE_URL + add_post_snippet + PINBOARD_AUTH_SNIPPET
response = requests.get(post_url, params=args)
# pdb.set_trace()
@ -35,6 +41,10 @@ def add_pin_url(reddit_dict):
def import_reddit_url_from_file(filename):
"""
imports a list of reddit URLs and meta data from a file.
returns a json object of that data.
"""
with open(filename, 'r') as infile:
data = json.loads(infile.read())
@ -43,11 +53,10 @@ def import_reddit_url_from_file(filename):
if __name__ == "__main__":
"""
You have to sleep for 3 seconds between requests or Maciej will Get Unhappy per
https://pinboard.in/api
You have to sleep for 3 seconds between requests or Maciej will Get Unhappy
per https://pinboard.in/api
"""
reddit_data = import_reddit_url_from_file("data.json")
for entry in reddit_data:
REDDIT_DATA = import_reddit_url_from_file("data.json")
for entry in REDDIT_DATA:
post_response = add_pin_url(entry)
time.sleep(3)
# print(post_response.text)

Loading…
Cancel
Save