class KsipApi: def __init__(self, server, login, password): self.__server = server self.__client = HttpClient( server, headers={'Content-type': 'application/json'}) self.__client.authorize_basic(login, password) def get_sdo_fact(self, uri, date, shift, mine, shaft, section): return self.__get_items('{0}/{1}/{2}/{3}/{4}/{5}'.format( uri, date, shift, mine, shaft, section)) def get_skip_fact(self, uri, date, shift, mine): response = self.__get_items('{0}/{1}/{2}/{3}'.format( uri, date, shift, mine), root='facts') return response def get_ore_pass_fact(self, uri, date, shift, mine): response = self.__get_items('{0}/{1}/{2}/{3}'.format( uri, date, shift, mine), root='facts') return response def __get_items(self, uri, root='data'): response = self.__client.get(uri) items = getattr(Dynamic(response), root, list()) if items is None: items = list() return items
def checkin(self): if not os.path.isfile(os.path.join(self.setting.conf, 'db2server.rsp')): self.logger.warning('Error: Configuration file not found.') sys.exit(1) else: self.logger.info('Configuration file found.') if not os.path.isfile( os.path.join(self.setting.storage, self.setting.file)): self.logger.info( 'Installation package file not found, will be download.') if self.setting.port == 21: ftpclient = FtpClient() self.logger.info('Downloading file %s ...' % self.setting.file) ftpclient.getData(self.setting) else: httpclient = HttpClient() self.logger.info('Starting download file %s ...' % self.setting.file) httpclient.getData(self.setting) else: self.logger.info('Installation package file found in %s .' % self.setting.storage) self.installation()
def post_data(self, result): client = HttpClient() log.info('Posting to {}'.format(self.url)) log.info('POST request: %s' % result) d = client.post(self.url, body=result, headers=self.headers) d.addCallback(self.parse_response, 'POST') d.addErrback(self.failure) return d
def main(): title = sys.argv[1] client = HttpClient() params = { 'action': 'query', 'format': 'json', 'prop': 'revisions', 'rvprop': 'content', 'titles': title, } data = client.get(URL, params) if data is not None: pprint(data) json.dump(data, open('contents.json', 'w')) # ファイルとして保存
def dump(): client = HttpClient() torrent_id = get_torrent_id() res = get_dump() new_records = [] last_torrent_id = torrent_id direction = Direction.UP if direction == Direction.UP: increment = 1 else: increment = -1 i = 0 failed = 0 while run: last_torrent_id = last_torrent_id + increment print str(last_torrent_id) link = 'http://rutor.is/torrent/' + str(last_torrent_id) response = client.get_response(link) if not response.has_error: parser = PageParser(last_torrent_id, response.response_text) valid = parser.is_valid() if valid: failed = 0 torrent_info = parser.parse() if torrent_info.category == u'Зарубежные фильмы' or torrent_info.category == u'Наши фильмы': res.append(torrent_info) new_records.append(torrent_info) else: print str(last_torrent_id) + ' is invalid' failed = failed + 1 if failed == 10: print 'end of torrent list reached' last_torrent_id = last_torrent_id - 10 - 1 break i = i + 1 time.sleep(4) dump = json.dumps(res, cls=MyEncoder, ensure_ascii=False) save_dump(dump) save_history(last_torrent_id + increment) save_to_db(new_records) print 'finished'
def main(): sys.argv.append( '{"url": "http://192.168.170.2/iso/virtio-win-0.1-74.iso", "port": 80, "md5": "dd2b02a0dc301ec580c27256d21a269c"}') setting = Setting() if setting.port == 21: ftpclient = FtpClient() print('Use ftp protocol to download.') print('Starting download file %s ... ' % setting.file) ftpclient.getData(setting) else: httpclient = HttpClient() print('Use http protocol to download.') print('Starting download file %s ... ' % setting.file) httpclient.getData(setting) print('Download competed.')
def __init__(self, config): self.__storage = Storage() self.__client = HttpClient(config.proxy, 10) self.__rates_service = NbrbRates(self.__client) self.__update_rates() self.__rates_scheduler = Scheduler(self.__update_rates) self.__rates_scheduler.start(3600 * 24, 00, 00)
def __init__(self, config): self.__storage = Storage() self.__client = HttpClient(config.proxy, 10) self.__weather_service = YahooWeatherApi(self.__client) self.__update_weather() self.__weather_scheduler = Scheduler(self.__update_weather) self.__weather_scheduler.start(3600, 00)
def main(): keyword = sys.argv[1] client = HttpClient() titles = search(client, keyword) pprint(titles) print(f'{len(titles)=}')
def main(): title = sys.argv[1] client = HttpClient() params = { 'action': 'query', 'format': 'json', 'prop': 'revisions', 'rvprop': 'content', 'titles': title, } data = client.get(URL, params) if data is not None: contents = get_contents(data) entities = get_entities(contents) pprint(entities) print('=' * 72) print('\nカテゴリのみを出力') for category in filter(lambda x: x.startswith('Category:'), entities): print(category)
def __init__(self, config): self.__client = HttpClient(config.proxy, 10) self.__vk_audio = VkAudio(config.vk_cookie, self.__client)
def __init__(self, config): self.__storage = Storage() self.__client = HttpClient(config.proxy, 10) self.__geo_service = YahooGeoApi(self.__client) self.__rutor_data_holder = RutorDataHolder('dump.txt')
def __init__(self, server, login, password): self.__server = server self.__client = HttpClient(server, {'Content-type': 'application/json'}) self.__client.authorize_bearer('token', login, password)
class DsgApi: def __init__(self, server, login, password): self.__server = server self.__client = HttpClient(server, {'Content-type': 'application/json'}) self.__client.authorize_bearer('token', login, password) def get_mine(self, date): return self.__get_items('api/references/mine/{0}'.format(date)) def get_shaft(self, date, mine_id): return self.__get_items('api/references/shaft/{0}/{1}'.format( date, mine_id)) def get_section(self, date, mine_id, shaft_id): return self.__get_items('api/references/section/{0}/{1}/{2}'.format( date, mine_id, shaft_id)) def get_orepass(self, date, mine_id): return self.__get_items('api/references/orepass/{0}/{1}'.format( date, mine_id)) def get_skip(self, date, mine_id): return self.__get_items('api/references/skip/{0}/{1}'.format( date, mine_id)) def get_location(self, date, mine_id): return self.__get_items('api/references/location/{0}/{1}'.format( date, mine_id)) def get_location_kind(self, date): return self.__get_items('api/references/locationkind/{0}'.format(date)) def get_development_type(self, date): return self.__get_items( 'api/references/developmenttype/{0}'.format(date)) def get_equipment_category(self, date): return self.__get_items( 'api/references/equipmentcategory/{0}'.format(date)) def get_equipment_type(self, date, equipment_category_id='Null'): return self.__get_items('api/references/equipmenttype/{0}/{1}'.format( date, equipment_category_id)) def get_equipment(self, date, mine_id, equipment_type_id='Null'): return self.__get_items('api/references/equipment/{0}/{1}/{2}'.format( date, mine_id, equipment_type_id)) def get_operator(self, date, mine_id): return self.__get_items('api/references/operator/{0}/{1}'.format( date, mine_id)) def get_material(self, date, material_kind='Null'): return self.__get_items('api/references/material/{0}/{1}'.format( date, material_kind)) def get_material_kind(self, date): return self.__get_items('api/references/materialkind'.format(date)) def get_job_kind(self, date, mine_id, job_category_id='Null'): return self.__get_items('api/references/jobkind/{0}/{1}/{2}'.format( date, mine_id, job_category_id)) def get_priority(self, date, mine_id, shift): return self.__get_items('api/references/priority/{0}/{1}/{2}'.format( date, mine_id, shift), root='priorityCollection') def get_unit(self, date): return self.__get_items('api/references/unit/{0}'.format(date)) def get_work_order(self, date, mine_id, shaft_id, section_id, shift): orders = self.__get_items('api/workorder/{0}/{1}/{2}/{3}/{4}'.format( date, mine_id, shaft_id, section_id, shift)) orders_list = list() if len(orders) > 0: for order in orders: orders_list = orders_list + order.body return orders_list def get_locomotive_order(self, date, shift, mine_id): return self.__get_items('api/locomotiveorder/{0}/{1}/{2}'.format( date, shift, mine_id)) def get_skip_order(self, date, shift, mine_id): return self.__get_items('api/skiporder/{0}/{1}/{2}'.format( date, shift, mine_id)) def __get_items(self, uri, root='data'): response = self.__client.get(uri) items = getattr(Dynamic(response), root) if items is None: items = list() return items
def __init__(self, server, login, password): self.__server = server self.__client = HttpClient( server, headers={'Content-type': 'application/json'}) self.__client.authorize_basic(login, password)
from client import HttpClient from rates import NbrbRates import datetime client = HttpClient(timeout=5) nbrb_rates = NbrbRates(client) print nbrb_rates.get_rate('USD', datetime.date(2017, 3, 12)) print nbrb_rates.get_today_rate('USD') print nbrb_rates.get_rates_dynamics('USD', datetime.date(2017, 3, 1), datetime.date(2017, 3, 31)) print nbrb_rates.get_currencies()
from client import AuthDecorator, HttpClient from flask import Flask, jsonify, request, g from flask_pymongo import PyMongo from auth import create_user, get_user_by_token, login_user from errors import APIError app = Flask(__name__) mongo_uri = 'mongodb://{}:{}@ds259325.mlab.com:59325/zql' app.config['MONGO_URI'] = mongo_uri.format(os.environ['ZQL_MONGO_USER'], os.environ['ZQL_MONGO_PASS']) mongo = PyMongo(app) # Initialize clients for all of our services. grammar = AuthDecorator(HttpClient('http://127.0.0.1:2666/')) interpreter = AuthDecorator(HttpClient('http://127.0.0.1:2020/')) postprocessing = AuthDecorator(HttpClient('http://127.0.0.1:2015/')) mapping = { # Interpreter Service forwarders 'interpret': interpreter, 'keywords': interpreter, # Grammar Service forwarders 'grammar': grammar, 'grammars': grammar, # Postprocessing Service forwarders 'event': postprocessing, 'events': postprocessing,