Browse Source

Build out skeleton for adding new pins from json file

- have still have to figure out how to /parse/ the json file
- still have to figure out how to post an item with arguments
master
jowj 3 years ago
parent
commit
298e11afb3
  1. 15
      main.py
  2. 25
      pinboard.py

15
main.py

@ -1,8 +1,9 @@
import pdb
import praw
import json
import os
import pdb
# Handle reddit requests
reddit = praw.Reddit(client_id=os.environ.get('REDDIT_ID'),
client_secret=os.environ.get('REDDIT_SECRET'),
user_agent='/u/ pynit-tasks',
@ -11,17 +12,19 @@ reddit = praw.Reddit(client_id=os.environ.get('REDDIT_ID'),
)
your_user = reddit.redditor(os.environ.get('REDDIT_UN'))
saved_posts = your_user.saved(limit=50)
saved_posts = your_user.saved(limit=1)
posts_to_save = []
for link in saved_posts:
if hasattr(link, 'is_self'):
posts_to_save.append([link.title, link.subreddit.display_name, link.author.name, link.selftext, link.url, link.permalink])
posts_to_save.append({'title':link.title, 'tag':link.subreddit.display_name, 'author':link.author.name, 'description':link.selftext, 'url':link.permalink})
elif hasattr(link, 'is_root'):
# pdb.set_trace()
posts_to_save.append([link.link_title, link.subreddit.display_name, link.author.name, link.body, link.link_url])
posts_to_save.append({'title':link.link_title, 'tag':link.subreddit.display_name, 'author':link.author.name, 'description':link.body, 'url':link.link_url})
else:
pdb.set_trace()
print("shit is fucked.")
# print(posts_to_save)
with open('data.json', 'w') as outfile:
json.dump(posts_to_save, outfile, indent=2)

25
pinboard.py

@ -1,13 +1,32 @@
import requests
import json
import os
import requests
import pysnooper
pinboard_token = os.environ.get("PINBOARD_TOKEN")
pinboard_base_url = "https://api.pinboard.in/v1/"
def get_all_posts():
posts = f"posts/all?auth_token={pinboard_token}"
pinboard_url = pinboard_base_url + posts
get_post_snippet = f"posts/all?auth_token={pinboard_token}"
pinboard_url = pinboard_base_url + posts_url_snippet
return requests.get(pinboard_url)
@pysnooper.snoop()
def add_pin_url(reddit_title, reddit_url, reddit_description, subreddit):
add_post_snippet = f"posts/add?auth_token={pinboard_token}"
args = {
'url': reddit_url,
'description': reddit_title,
'extended': reddit_description,
'tags': subreddit,
'replace': no
}
pass
def import_reddit_url_from_file(filename):
with open(filename, 'r') as infile:
json.load(infile)
import_reddit_url_from_file("data.json")

Loading…
Cancel
Save