Skip to content

Commit

Permalink
add local archive json to work around pocket bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Sveder committed Oct 8, 2024
1 parent 8cb5ec9 commit 90d2dd0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions pocket_skipper/archived.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["4110883129", "4110064793", "4110079295", "4109418231", "4110064793", "4109480786", "4108677704", "4109551949", "4109551961", "4108311649", "4108168029", "4107756831", "4106786426", "4107204026", "4108311670", "4106790312", "4106176807", "4112055280", "4112596511", "4112558383", "4112471475", "4112466521", "4112471464", "4112464294", "4116147259", "4116147259"]
31 changes: 26 additions & 5 deletions pocket_skipper/theapp/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import json
import pprint
import traceback
Expand All @@ -13,9 +14,9 @@
POCKET_OAUTH_REQUEST_URL = "https://getpocket.com/v3/oauth/request"
POCKET_OAUTH_AUTHORIZE_URL = "https://getpocket.com/v3/oauth/authorize"
POCKET_OAUTH_GET_ALL_URL = "https://getpocket.com/v3/get"
POCKET_OAUTH_ARCHIVE_URL = "https://getpocket.com/v3/send?%s"
POCKET_OAUTH_ARCHIVE_URL = "https://getpocket.com/v3/send?"

POCKET_OAUTH_CONSUMER_KEY = "11798-8b31a6c8596a31af57059a0e"
POCKET_OAUTH_CONSUMER_KEY = ""

POCKET_REDIRECT_URL = "http://%s/skipper" # % domain_url

Expand Down Expand Up @@ -100,18 +101,26 @@ def skipper(request):
del request.session["token"]
request.session.modified = True
return shortcuts.redirect("/pocket")

reading_list_data = json.loads(response)
reading_list = reading_list_data["list"]
if reading_list == []:
reading_list = {}

items = list(reading_list.values())

items = [item for item in items if "time_added" in item]

# Sort by date:
items.sort(key=lambda x: x["time_added"])
items.reverse()

try:
if os.path.exists('archived.json'):
archived = json.load(open('archived.json'))
items = [item for item in items if item["item_id"] not in archived]

except Exception as e:
print("Failed to load archived items.")

# Make sure the item has a name, or just show the url if not:
for item in items:
item["fool_proof_title"] = item.get("resolved_title", False) or \
Expand Down Expand Up @@ -146,6 +155,18 @@ def mark_as_read(request):
if not item_id:
raise Exception('item_id must be provided.')

try:
if os.path.exists('archived.json'):
archived = json.load(open('archived.json'))
archived.append(item_id)
json.dump(archived, open('archived.json', 'w'))
else:
archived = [item_id]
json.dump(archived, open('archived.json', 'w'))

except Exception as e:
print("Failed to load archived items.")

try:
actions = [{
"action": "archive",
Expand Down

0 comments on commit 90d2dd0

Please sign in to comment.