def __init__(self, **kwargs): """ constructor """ super().__init__() self._queuename = self.__class__._queuename self._dateformat = self.__class__._dateformat self._datetimeformat = self.__class__._datetimeformat """ parse **kwargs in tmp dict var """ for key, default in vars(self.__class__).items(): if not key.startswith('_') and key != '': if (not key in vars(QueueMessage).items()): if key in kwargs: value = kwargs.get(key) to_type = type(default) if to_type is StorageTableCollection: setattr(self, key, value) elif to_type is datetime.datetime: setattr( self, key, safe_cast(value, to_type, default, self._datetimeformat)) elif to_type is datetime.date: setattr( self, key, safe_cast(value, to_type, default, self._dateformat)) else: setattr(self, key, safe_cast(value, to_type, default)) else: setattr(self, key, default)
def complete(model: GenModel, error_message: str = ''): helper.flush_input() caption: str = f'Enter the parameters of the {model.name}:' parameters: dict = model.parameters # init curses_helper curses_helper.init() # write an error message if it exists curses_helper.write_formatted("{0}", error_message) # write a caption curses_helper.write_formatted("{0, 2} {1, 1}\n", chr(9679), caption) previous_value_dict = {} # start parameters input loop for k, v in parameters.items(): if not v['constant']: # we should check whether the user's input is correct while 1: __write_input_request(k, v['value']) value = curses_helper.read( allow_single_dot=isinstance(v['value'], float)) if value == '': value = str(v['value']) curses_helper.move_line_home(-1) __write_input_request(k, value, end=value + '\n') break # notify a user that input value is not correct if helper.safe_cast(value, int, None) is None and helper.safe_cast( value, float, None) is None: curses_helper.move_line_home(-1) curses_helper.write_formatted( "{0,4} {1,1}", chr(9679), "Input value must be a positive number! Press Enter to try again." ) curses_helper.read() curses_helper.move_line_home(-1) else: break # if the input is correct then break loop previous_value_dict[k] = str(v['value']) v['value'] = type(v['value'])(value) curses_helper.close() for k, v in model.param_conditions.items(): condition = v.format('model.parameters') if not eval(condition): return complete( model, "An error occurred while checking the conditions of the model parameters: \n" "\t{0}\n\n".format(k)) return True
def __init__(self, **kwargs): """ constructor """ self._tablename = self.__class__._tablename self._dateformat = self.__class__._dateformat self._datetimeformat = self.__class__._datetimeformat self._exists = None """ parse **kwargs into instance var """ self.PartitionKey = kwargs.get('PartitionKey', '') self.RowKey = kwargs.get('RowKey', '') for key, default in vars(self.__class__).items(): if not key.startswith('_') and key != '': if key in kwargs: value = kwargs.get(key) to_type = type(default) if to_type is StorageTableCollection: setattr(self, key, value) elif to_type is datetime.datetime: setattr( self, key, safe_cast(value, to_type, default, self._datetimeformat)) elif to_type is datetime.date: setattr( self, key, safe_cast(value, to_type, default, self._dateformat)) else: setattr(self, key, safe_cast(value, to_type, default)) else: setattr(self, key, default) """ set primary keys from data""" if self.PartitionKey == '': self.__setPartitionKey__() if self.RowKey == '': self.__setRowKey__() """ initialize collectionobjects """ self.__setCollections__() """ define properties to be encrypted """ self.__setEncryptedProperties__() pass
def getgenrefromid(self, id): """ has to be overwritten """ for genre in self._collection: if genre['Genre_Id'] == safe_cast(id, int, 0): return genre['Genre'] break return 'Sonstiges'
def get(self): """ list top recordings with filters """ """ retrieve Boards with filters """ toplist = StorageTableCollection('recordings', "PartitionKey eq 'top'") toplist = db.query(toplist) toplist.sort(key=lambda item: item.beginn, reverse=True) """ apply filters """ for key, value in request.args.items(): if key == 'Genre': toplist.filter('genre', value) elif key == 'Channel': toplist.filter('sender', value) elif key == 'Sort': reverse = safe_cast(request.args.get('Descending', False), bool) field = recording[value].attribute log.debug('Sort field = {} with reverse {!s}'.format( field, reverse)) toplist = sorted(toplist, key=lambda k: k[field], reverse=reverse) elif key == 'Descending': if not request.args.get('Sort', False): api.abort(403, __class__._responses['get'][403]) else: api.abort(403, __class__._responses['get'][403]) """ abort if no toplist filtered """ if toplist == 0: api.abort(404, __class__._responses['get'][404]) """ return list, httpstatus """ return toplist, 200
def beforerequestlogic(): """ parse request data """ if not 'platform' in session: platform = str.lower( request.args.get('cordovaplatform', request.user_agent.platform)) if not platform in ['android', 'ios']: session['platform'] = config['APPLICATION_UI_DEFAULT'] else: session['platform'] = platform if not 'clientid' in session: session['clientid'] = request.args.get('clientid', config['APPLICATION_CLIENT_ID']) if not 'deviceuuid' in session: session['deviceuuid'] = request.args.get('deviceuuid', '') g.platform = session['platform'] g.clientid = session['clientid'] g.deviceuuid = session['deviceuuid'] """ user = default """ g.user = None """ message """ messageid = safe_cast(request.args.get('messageid', 0), int) g.message = Message() g.message.text = 'Entschuldigung! Diese Funktion wird noch entwickelt und steht in dieser Verion von otrrent noch nicht zu Verfügung.' if messageid == 1: g.message.header = 'Bewerten Sie otrrent' g.message.error = True g.message.show = True elif messageid == 2: g.message.header = 'Nutzen Sie otrrent Werbefrei!' g.message.error = True g.message.show = True elif messageid == 3: g.message.header = 'Nutzen Sie otrrent als Pro-User!' g.message.error = True g.message.show = True elif messageid == 4: g.message.header = 'Fehler' g.message.text = 'Bitte nutzen Sie die otrrent App! Sie sind nicht eingelogged' g.message.error = True g.message.show = True elif messageid == 5: g.message.header = 'Konfiguration' g.message.text = 'Bitte pflegen Sie Ihren Endpoints für torrent oder Videodateien' g.message.error = True g.message.show = True
def read(caption: str = '', allow_single_dot: bool = False): write(caption) curses.cbreak() curses.noecho() input_str, c = '', '' while c != 10: c = src.getch() c_str = str(safe_cast(c, chr, '')) if c == 8 or c == 127 or c == curses.KEY_BACKSPACE: if len(input_str) != 0: src.addstr("\b \b") input_str = input_str[:-1] elif (c_str.isprintable() and c_str.isdecimal()) or c == 10 or ( allow_single_dot and ('.' not in input_str and c_str == '.')): src.addstr(c_str) input_str += c_str curses.echo() curses.nocbreak() return input_str.replace('\n', '')
def update_torrents(startdate: date, config, log): """ rufe alle torrents der letzten 8 Tage ab und ordne diese einem top recording zu https://www.onlinetvrecorder.com/v2/?go=tracker&search=&order=ctime%20DESC&start=0 """ log.debug('try to update torrents webcontent...') stopflag = False start = 0 torrentlist = [] db.register_model(Torrent()) while not stopflag: """ download webcontent into content""" with urllib.request.urlopen( 'https://www.onlinetvrecorder.com/v2/?go=tracker&search=&order=ctime%20DESC&start=' + str(start)) as response: content = response.read() """ für jeden Eintrag in ID= searchrow """ content = str(content.decode('utf-8', 'ignore')).split( ' class="bordertable">')[1].split('</table>')[0].split('</tr>') for index in range(1, len(content) - 1): lines = content[index].split('</td>') """ parse data from entry """ torrentlink = lines[1].split("href='")[1].split("'")[0] torrentfile = lines[1].split(torrentlink + "'>")[1].split('</a>')[0] finished = safe_cast(lines[2].split('>')[1].split('</td>')[0], int, 0) loading = safe_cast(lines[3].split('>')[1].split('</td>')[0], int, 0) loaded = safe_cast(lines[4].split('>')[1].split('</td>')[0], int, 0) fileparts = torrentfile.split(' ') beginn = safe_cast( fileparts[len(fileparts) - 4] + ' ' + fileparts[len(fileparts) - 3] + '-00', datetime, None, '%y.%m.%d %H-%M-%S') sender = fileparts[len(fileparts) - 2] if beginn.date() >= startdate: """ update list """ torrent = {} torrent['TorrentLink'] = torrentlink torrent['TorrentFile'] = torrentfile torrent['finished'] = finished torrent['loading'] = loading torrent['loaded'] = loaded torrent['beginn'] = beginn torrent['sender'] = sender.replace(' ', '').lower() resolution = '' resolution = torrentlink.split('TVOON_DE')[1].split( 'otrkey.torrent')[0] if resolution == ('.mpg.HD.avi.'): """ TVOON_DE.mpg.HD.avi.otrkey.torrent""" resolution = 'HD' elif resolution == ('.mpg.HQ.avi.'): """ _TVOON_DE.mpg.HQ.avi.otrkey.torrent""" resolution = 'HQ' elif resolution == ('.mpg.avi.'): """ DIVX _TVOON_DE.mpg.avi.otrkey.torrent """ resolution = 'DIVX' elif resolution == ('.mpg.mp4.'): """ MP4 0_TVOON_DE.mpg.mp4.otrkey.torrent """ resolution = 'MP4' elif resolution == ('.mpg.HD.ac3.'): """ f1_130_TVOON_DE.mpg.HD.ac3.otrkey.torrent """ resolution = 'HD.AC3' else: resolution = 'AVI' torrent['Resolution'] = resolution torrentlist.append(torrent) #log.debug('parsed torrent: {} in {} recorded at {!s} on {}'.format(torrentfile, resolution, beginn, sender)) else: stopflag = True break start = start + 50 log.info('{!s} torrents successfully retrieved...'.format( len(torrentlist))) """ retrieve epg id from top recordings """ tops = StorageTableCollection('recordings', "PartitionKey eq 'top'") tops = db.query(tops) for top in tops: torrents = [ item for item in torrentlist if item['beginn'].strftime('%y.%m.%d %H-%M-%S') == top.beginn.strftime('%y.%m.%d %H-%M-%S') and item['sender'] == top.sender.replace(' ', '').lower() ] log.debug('filterded {!s} torrents for top recording {}'.format( len(torrents), top.titel)) if len(torrents) >= 1: """ Torrent Count """ topItem = Recording(**top) topItem.torrentCount = len(torrents) db.insert(topItem) """ Insert Torrent """ for torrent in torrents: db.insert(Torrent(Id=top.Id, **torrent)) else: db.delete(Torrent(Id=top.Id, **torrent)) db.delete(Recording(**top))
""" imports & globals """ import os from sys import stderr, stdout, stdin import logging import logging.handlers from helpers.helper import safe_cast """ Main configuration """ config = {} """ import configuration depending on environment """ config['APPLICATION_ENVIRONMENT'] = safe_cast( os.environ.get('APPLICATION_ENVIRONMENT'), str, 'Production') config['APPLICATION_UI_DEFAULT'] = safe_cast( os.environ.get('APPLICATION_UI_DEFAULT'), str, 'ios') config['APPLICATION_VERSION'] = safe_cast( os.environ.get('APPLICATION_VERSION'), str, '0.0.0') if config['APPLICATION_ENVIRONMENT'] == 'Development': from config.application import dev as configs elif config['APPLICATION_ENVIRONMENT'] == 'Test': from config.application import test as configs elif config['APPLICATION_ENVIRONMENT'] == 'Production': from config.application import prod as configs else: from config.application import prod as configs tmpconfig = {} for (key, value) in vars(configs).items(): if key != '' and key[:2] != '__': tmpconfig[key] = value