Skip to content

Instantly share code, notes, and snippets.

@jbfriedrich
Created June 26, 2023 21:56
Show Gist options
  • Save jbfriedrich/78f4fa457bdb1ee33cc955614316ba25 to your computer and use it in GitHub Desktop.
Save jbfriedrich/78f4fa457bdb1ee33cc955614316ba25 to your computer and use it in GitHub Desktop.
Delete entries from your pocket list that are older than a day
#!/usr/bin/env python
# pocket-appi module, not pocket
from pocket import Pocket, PocketException
import datetime as dt
p = Pocket(
consumer_key='myconsumerkey',
access_token='myaccesstoken'
)
now = dt.datetime.now()
timeago = dt.timedelta(days=1)
then = now - timeago
unixtime = int(then.timestamp())
pl = p.retrieve()
for i in pl['list']:
url = pl['list'][i]['given_url']
etime = int(pl['list'][i]['time_added'])
etime_readable = dt.datetime.fromtimestamp(etime).strftime(
'%Y-%m-%d %H:%M:%S'
)
if etime < unixtime:
print('Delete post {} ({}) with timestamp {}...'.format(
i, url, etime_readable)
)
try:
p.delete(i).commit()
except PocketException as e:
print(e.message)
# Fetch a list of articles
# try:
# print(p.retrieve(offset=0, count=10))
# except PocketException as e:
# print(e.message)
# Add an article
# p.add('https://pymotw.com/3/asyncio/')
# Start a bulk operation and commit
# p.archive(1186408060).favorite(1188103217).tags_add(
# 1168820736, 'Python'
# ).tags_add(
# 1168820736, 'Web Development'
# ).commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment