11# coding=utf-8
22import json
33import os .path
4- import pickle
54import requests
65import time
76import threading
1918from tasks import Tasks
2019
2120
21+ PICKLE_FILENAME = "deletionIDs.p"
22+
23+
2224# noinspection PyClassHasNoInit,PyBroadException,PyMethodParameters
2325class DeletionWatcher :
2426 next_request_time = time .time () - 1
@@ -33,12 +35,11 @@ def __init__(self):
3335 log ('error' , 'DeletionWatcher failed to create a websocket connection' )
3436 return
3537
36- if os .path .exists ("deletionIDs.p" ):
37- with open ("deletionIDs.p" , "rb" ) as fh :
38- for post in DeletionWatcher ._check_batch (pickle .load (fh )):
39- self .subscribe (post , pickle = False )
40-
41- self ._save ()
38+ if datahandling ._has_pickle (PICKLE_FILENAME ):
39+ pickle_data = datahandling ._load_pickle (PICKLE_FILENAME )
40+ for post in DeletionWatcher ._check_batch (pickle_data ):
41+ self .subscribe (post , pickle = False )
42+ self ._save ()
4243
4344 threading .Thread (name = "deletion watcher" , target = self ._start , daemon = True ).start ()
4445
@@ -113,8 +114,7 @@ def _save(self):
113114 else :
114115 pickle_output [post_site ].append (post_id )
115116
116- with open ("deletionIDs.p" , "wb" ) as pickle_file :
117- pickle .dump (pickle_output , pickle_file )
117+ datahandling ._dump_pickle (PICKLE_FILENAME , pickle_output )
118118
119119 @staticmethod
120120 def _check_batch (saved ):
0 commit comments