Skip to content

Instantly share code, notes, and snippets.

@Sg4Dylan
Created May 30, 2023 07:24
Show Gist options
  • Save Sg4Dylan/3a757a51921f8abd8c499ea801f2f4f7 to your computer and use it in GitHub Desktop.
Save Sg4Dylan/3a757a51921f8abd8c499ea801f2f4f7 to your computer and use it in GitHub Desktop.
Remove outdated RSS records for qBittorrent
import os
import json
import re
from datetime import datetime, timedelta
rss_json = ''
for i in os.listdir('.'):
if i.endswith('.json'):
rss_json = i
pattern = re.compile(r'([\d]{4}-[\d]{2}-[\d]{2}T.*?$)')
def check_month_old(metainfo):
# extract time string
torrent = metainfo.get('torrent', '')
match = pattern.search(torrent)
if not match:
return False
time_string = match.group()
# parse timedate & check
format = "%Y-%m-%dT%H:%M:%S.%f"
if "." not in time_string:
format = "%Y-%m-%dT%H:%M:%S"
time = datetime.strptime(time_string, format)
now = datetime.now()
one_month_ago = now - timedelta(days=30)
if time < one_month_ago:
return True
return False
rss = json.loads(open(rss_json, 'rb').read())
rss_new = [i for i in rss if not check_month_old(i)]
with open(rss_json, 'w') as f:
json.dump(rss_new, f, indent=4)
print(f"Removed: {len(rss) - len(rss_new)}/{len(rss)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment