def updateCache(): updateprocesspath = tempfile.gettempdir() + '/updateProcess' open(updateprocesspath, 'w').write('updating') try: updateid() sleep(10) updateTimeTables() sleep(10) updateSubstitution() sleep(10) updateNews() except Exception: try: open(updateprocesspath, 'w').write('error---') log.error('Błąd przy aktualizacji cache!', str(traceback.format_exc())) email = EmailMessage('Blad przy aktualizacji cache!!!', 'Treść błędu: ' + str(traceback.format_exc()), to=['*****@*****.**']) email.send() return except Exception: log.critical('Podwójny błąd przy aktualizacji cache!', str(traceback.format_exc())) return open(updateprocesspath, 'w').write('finished')
def timetableJob(): create_new_session() log.info("Updating timetable") credentials = retrieve_pass() if credentials is None: return connection_count = 0 for filename in os.listdir(get_cur_path() + '/timetables'): name = os.path.splitext(filename)[0] typ = name.replace('#', '-').split('-') uid = typ[1] typ = typ[0] if '#' in name: uid = '#' + str(uid) elif '-' in name: uid = '-' + str(uid) else: log.error('Could not determine uid. Omitting update for: ' + name) continue log.info('Downloading timetable: ' + name) plan = download_and_regenerate_timetable(uid, typ, credentials) save_dict(name, plan) connection_count += 1 if connection_count % 10 == 0: create_new_session() credentials = retrieve_pass() if credentials is None: return sleep(2)
def retrieve_pass(): for _ in range(0, 3): try: credentials = regenerate_pass() return credentials except json.JSONDecodeError: log.info('Retrieving password failed. Trying again...') else: log.error('Failed to retrieve password!!!') return None
def loadSubstiution(date): verifyInput(date) if not os.path.exists(CACHE_LOCATION + 'substitution'): os.makedirs(CACHE_LOCATION + 'substitution') try: with open(CACHE_LOCATION + 'substitution/' + date + '.sbt', 'rb') as f: return pickle.load(f) except FileNotFoundError: if DEBUG: log.info('Tryb DEBUG aktywny - rozpoczynam pobieranie zastępstw') updateSubstitution() raise SubstitutionException( 'Try debugowania jest aktywny. Pobrano zastępstwa. Odśwież stronę.' ) else: log.error('Brak pliku z zastępstwami na ' + date) raise SubstitutionException( 'Zastępstwa na żądany dzień nie istnieją')
def loadTimeTable(selector, uid): verifyInput(selector, uid) if not os.path.exists(CACHE_LOCATION + 'timetables'): os.makedirs(CACHE_LOCATION + 'timetables') try: with open( CACHE_LOCATION + 'timetables/' + selector + uid.replace('*', '#') + '.tt', 'rb') as f: return pickle.load(f) except FileNotFoundError: if DEBUG: log.info( 'Tryb DEBUG aktywny - rozpoczynam pobieranie planów lekcji') updateTimeTables() raise TimeTableException( 'Tryb debugowania jest aktywny. Pobrano plany lekcji. Odśwież stronę.' ) else: log.error('Brak pliku z planem lekcji dla ' + selector + ' ' + uid) raise TimeTableException('Żądany plan lekcji nie istnieje')
# Chciałbym z tego miejsca podziękować Przemub'owi za naprowadzenie mnie na rozwiązanie bug'a # Dziękuję !!! import os import random import urllib.request import urllib.parse import chmura.log as log from lo3.settings import ENABLE_TOR, ENABLE_AGGRESSIVE_IP_CHANGE, DEBUG from time import sleep if DEBUG: log.error('Debug mode is active!!! Do not use it in production!') if ENABLE_TOR: log.info('TOR forwarding enabled') else: log.error('TOR not enabled!!!') if ENABLE_AGGRESSIVE_IP_CHANGE: from stem import Signal from stem.control import Controller log.info('Aggressive IP changing is active!') USER_AGENTS_LIST = [ 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 16.0; rv:42.0) Gecko/20100101 Firefox/42.0', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36', 'Mozilla/5.0 (Windows NT 7.1; Win64; x64; rv:56.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2704.103 Safari/537.36', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41',
import os import urllib.request import urllib.parse import chmura.log as log from lo3.settings import DEFAULT_USER_AGENT, ENABLE_TOR, ENABLE_AGGRESSIVE_IP_CHANGE, DEBUG if DEBUG: log.error('Debug mode is active!!! Do not use it in production!') if ENABLE_TOR: log.info('TOR forwarding enabled') else: log.warning('TOR not enabled!!!') if ENABLE_AGGRESSIVE_IP_CHANGE: from stem import Signal from stem.control import Controller log.warning('Aggressive IP changing is active!') def get_cur_path(): return os.path.dirname(os.path.abspath(__file__)) def getReversedDict(dictionary, key): for d in dictionary: if dictionary[d] == key: return d return "null"