コード例 #1
0
                                                                 database=self.config['storage_app']['database_name'])
        payload = {'presenter': presenter}
        r = requests.get(url, params=payload)

        if r.status_code != 200:
            log('Database returned response code %d.' % r.status_code)
            log('Please check StorageApp log, collection or collection field may not exist.')
            return r.status_code

        # parse text
        response_dict = json.loads(r.text)

        # get presenter's name
        presenter_name = response_dict['name']
        presenter_position = response_dict['position']
        presenter_social = response_dict['vkpage']

        # returns string
        log('Returning presenter info: {name}, position: {position}, social: {social}'.format(name=presenter_name,
                                                                                              position=presenter_position,
                                                                                              social=presenter_social))
        return ','.join([presenter_name, presenter_position, presenter_social])


if __name__ == '__main__':
    s = StorageRavager(json_reader('config.json'))
    s.get_team_short_name('Арсенал')
    s.get_team_logo("Арсенал")  # "Хвачхон КСПО (жен)"
    s.get_team_short_name_localized('Арсенал')

コード例 #2
0
    teams = db[collection]

    # search in collection
    team_document = teams.find_one({"name_olimp": request.args['team']})

    # handle empty result
    try:
        return json.dumps(team_document, cls=JSONEncoder)
    except Exception as e:
        log('An exception occurred: %s' % e)
        return str(e)


if __name__ == '__main__':

    # settings
    # read config
    json_config = json_reader('config.json')
    MONGO_HOST = json_config['mongo']['host']
    MONGO_PORT = json_config['mongo']['port']
    storage_app_host = json_config['storage_app']['host']
    storage_app_port = json_config['storage_app']['port']

    # init client for 'media' database
    client = MongoClient(MONGO_HOST, int(MONGO_PORT))
    log('Created MongoDB client.')

    # starting database manager
    log('Starting database manager...')
    app.run(debug=False, host=storage_app_host, port=storage_app_port)
コード例 #3
0
        log('Moving {name} to {path}...'.format(name=name, path=path))
        shutil.move(original_full_file_path, os.path.join(new_file_path, name))

    def run(self):
        log('Distribution service is running...')
        while True:
            for root in self.roots:
                # update file list
                self.lookup(root)

                # generate paths for found files
                for name in self.file_dict:
                    self.process_filename(name, root)

                # move files and delete (not copy), log it
                names_to_delete = []
                for name, path in self.file_dict.items():
                    self.move_to_new_path(path, name, root)
                    names_to_delete.append(name)

                # deleting processed file from files_dict
                for name in names_to_delete:
                    log('Removing deleted file name from files dict: %s' %
                        self.file_dict.pop(name, None))


if __name__ == '__main__':
    config = json_reader('./../config.json')
    ds = DistributionService(config)
    ds.run()
コード例 #4
0
                return False
        else:
            log('Unable to parse outcome because its empty.')

    def prepare_outcomes_string(self):
        keys = []
        values = []
        for key, value in self.outcome_dict.items():
            keys.append(key)
            values.append(value)
        return ','.join(keys) + '\n' + ','.join(values)


def parse_13_digits_timestamp(timestamp, return_template):
    # full template: your_dt.strftime("%Y-%m-%d %H:%M:%S")
    your_dt = datetime.datetime.fromtimestamp(int(timestamp) / 1000)
    if return_template == 'hh:mm':
        return your_dt.strftime("%H:%M")


if __name__ == '__main__':
    # Хёндай Стиил (жен) - Хвачхон КСПО (жен)
    # Ливерпуль - Норвич Сити
    j = JsonBlazer(json_reader('config.json'))
    j.return_all_topics()
    j.parse_json()
    # j.return_bet_types('Ливерпуль - Норвич Сити')
    # j.return_outcomes('Ливерпуль - Норвич Сити', 'main')
    j.return_outcomes_no_names('Ливерпуль - Норвич Сити', 'main')
    # j.return_outcome('Хёндай Стиил (жен) - Хвачхон КСПО (жен)', 'main')
コード例 #5
0
                    file=self.config['data_source'][source]['file']))
                try:
                    r = requests.get(self.config['data_source'][source]['url'], auth=self.creds)
                    if r.status_code == 200:
                        with open(self.config['data_source'][source]['file'], 'w+', encoding='utf-8') as fd:
                            response_json = json.dumps(r.text, ensure_ascii=False).encode('utf-8')
                            fd.write(response_json.decode('utf-8'))
                            log('JSON from {url} written.'.format(url=self.config['data_source'][source]['url']))
                            log('JSON file {file} updated.'.format(file=self.config['data_source'][source]['file']))
                    else:
                        log('Unable to get JSON: status_code = %d' % r.status_code)
                except requests.ConnectionError:
                    log('Unable to connect to {url}.'.format(url=self.config['data_source']['test_source']['url']))
        else:
            log('No json_data sources configured: stopping')
            self.running = False

    def run(self):
        while self.running:
            self.update()
            self.refresh_data()

            # wait before starting next update
            time.sleep(self.wait / 2)


if __name__ == '__main__':
    ju = JsonUpdaterDaemon(json_reader('config.json'))
    # ju.run()
    # ju.update()