<commit_before>import subprocess
import datetime
import requests
import json
import globals
import os
import pprint
import re
import sys

# check if files downloadde
with open(globals.json_weekly, "r") as readfile:
    queue_transmission = json.load(readfile)

data_rpc_tg={
        "method":"torrent-get",
        "arguments": {
            "fields": ["id","name","files","status","doneDate"]
            }
        }

data_rpc_tr={
        "method":"torrent-remove",
        "arguments": {
            "ids": [],
            "delete-local-data": True
            }
        }

TR_STATUS_STOPPED        = 0 # /* Torrent is stopped */
TR_STATUS_CHECK_WAIT     = 1 # /* Queued to check files */
TR_STATUS_CHECK          = 2 # /* Checking files */
TR_STATUS_DOWNLOAD_WAIT  = 3 # /* Queued to download */
TR_STATUS_DOWNLOAD       = 4 # /* Downloading */
TR_STATUS_SEED_WAIT      = 5 # /* Queued to seed */
TR_STATUS_SEED           = 6 # /* Seeding */

session = requests.Session()

r1 = session.post(globals.url_rpc, auth=(globals.user_rpc, globals.passwd_rpc)) #, data=data_rpc)

if r1.status_code == 409:
    header_session_id = {"x-transmission-session-id": r1.headers["x-transmission-session-id"]}
    r2 = session.post(globals.url_rpc, auth=(globals.user_rpc, globals.passwd_rpc), headers=header_session_id)

# get list from torrent-get for all torrents, then go through 1 by 1, it the torrent is longer than n days, delete it.
r3 = session.post(globals.url_rpc, auth=(globals.user_rpc, globals.passwd_rpc), headers=header_session_id, data=json.dumps(data_rpc_tg))

r3json = r3.json()

ids = []

if r3json.get("result") == "success":
    for item in r3json["arguments"]["torrents"]:
        done = datetime.datetime.fromtimestamp(item["doneDate"])
        now = datetime.datetime.now()
        diff = now.day - done.day

        print item["id"], diff, item["status"], item["name"],
        if item["status"] == TR_STATUS_SEED and diff > globals.max_share_days:
            print ", removed"   
            ids.append(item["id"])
<commit_msg>get day delta from timedelta.days<commit_after>import subprocess
import datetime
import requests
import json
import globals
import os
import pprint
import re
import sys

# check if files downloadde
with open(globals.json_weekly, "r") as readfile:
    queue_transmission = json.load(readfile)

data_rpc_tg={
        "method":"torrent-get",
        "arguments": {
            "fields": ["id","name","files","status","doneDate"]
            }
        }

data_rpc_tr={
        "method":"torrent-remove",
        "arguments": {
            "ids": [],
            "delete-local-data": True
            }
        }

TR_STATUS_STOPPED        = 0 # /* Torrent is stopped */
TR_STATUS_CHECK_WAIT     = 1 # /* Queued to check files */
TR_STATUS_CHECK          = 2 # /* Checking files */
TR_STATUS_DOWNLOAD_WAIT  = 3 # /* Queued to download */
TR_STATUS_DOWNLOAD       = 4 # /* Downloading */
TR_STATUS_SEED_WAIT      = 5 # /* Queued to seed */
TR_STATUS_SEED           = 6 # /* Seeding */

session = requests.Session()

r1 = session.post(globals.url_rpc, auth=(globals.user_rpc, globals.passwd_rpc)) #, data=data_rpc)

if r1.status_code == 409:
    header_session_id = {"x-transmission-session-id": r1.headers["x-transmission-session-id"]}
    r2 = session.post(globals.url_rpc, auth=(globals.user_rpc, globals.passwd_rpc), headers=header_session_id)

# get list from torrent-get for all torrents, then go through 1 by 1, it the torrent is longer than n days, delete it.
r3 = session.post(globals.url_rpc, auth=(globals.user_rpc, globals.passwd_rpc), headers=header_session_id, data=json.dumps(data_rpc_tg))

r3json = r3.json()

ids = []

if r3json.get("result") == "success":
    for item in r3json["arguments"]["torrents"]:
        done = datetime.datetime.fromtimestamp(item["doneDate"])
        now = datetime.datetime.now()
        diff = now.day - done.day
        diff = now - done
        
        try:
            print item["id"], diff.days, item["status"], item["name"],
        except:
            pass

        if item["status"] == TR_STATUS_SEED and diff.days > globals.max_share_days:
            print ", removed"   
            ids.append(item["id"])

{'fraction_non_alphanumeric': 0.13312693498452013, 'fraction_numerical': 0.010002381519409383, 'mean_word_length': 2.903345724907063, 'pattern_counts': {'":': 18, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2174292', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1349, 'n_words': 308}