def __init__(self, code): self.code = code self.data = pandas.read_csv('backend/posts.csv') self.flairs = {} self.r = Requests(code) self.name = self.r.getName() self.total_flairs = 0
def __init__(self, settings_inst): '''CONSTRUCTOR''' MessageParser.__init__(self) Requests.__init__(self, True) self.__host = settings_inst.GetSettings('master_ip') self.__server_port = settings_inst.GetSettings('port') self.__buffer_size = settings_inst.GetSettings('master_buffer_size') self.__max_send_size = settings_inst.GetSettings('slave_buffer_size') self.__timeout = settings_inst.GetSettings('tcp_timeout') self.__print_payload_info = settings_inst.GetSettings('print_payload_info') self.__connected = False
def updateProxies(self): updated = False self._proxies = [] requestText = Requests.getText(self.getUrl()) if requestText != None: soup = BeautifulSoup(requestText, "html.parser") table = soup.find("table", {"id": "proxylisttable"}) if table != None: soup = BeautifulSoup(str(table), "html.parser") tableBody = soup.find("tbody") if tableBody != None: soup = BeautifulSoup(str(tableBody), "html.parser") tableRows = soup.find_all("tr") if tableRows != None: for i in tableRows: soup = BeautifulSoup(str(i), "html.parser") rowColumns = soup.find_all("td") if rowColumns != None and len(rowColumns) >= 5: self._proxies.append( (str(rowColumns[0]) + ":" + str(rowColumns[1]) + "#" + str(rowColumns[2]) + "#" + str(rowColumns[4])).replace( "<td>", "").replace("</td>", "")) updated = True if not updated: self._proxies = []
class Analysis(): def __init__(self, code): self.code = code self.data = pandas.read_csv('backend/posts.csv') self.flairs = {} self.r = Requests(code) self.name = self.r.getName() self.total_flairs = 0 def findFlairs(self): for i in range(len(self.data)): if (self.name or self.code) in (self.data.loc[i, 'Title'].upper()): if self.data.loc[i, 'Flair'] in self.flairs: self.flairs[self.data.loc[i, 'Flair']] += 1 self.total_flairs += 1 else: self.flairs[self.data.loc[i, 'Flair']] = 1 self.total_flairs += 1 def return_prediction(self): voilitity = (self.flairs['Discussion'] + self.flairs['DD'] + self.flairs['YOLO'] + self.flairs['Options'] - self.flairs['Fundamentals']) / self.total_flairs try: score = (self.flairs['Gain'] - self.flairs['Loss']) * voilitity # 0 to 100 except: score = 0 t = self.r.getAnalysis() b = t['buy'] s = t['sell'] sb = t['strongBuy'] ss = t['strongSell'] finScore = (2 * sb + b - s - 2 * ss) / (b + s + sb + ss) return (finScore + score) / 2
pass @staticmethod def __format_json(self, payload): text = json.dumps(payload, sort_keys=True, indent=4) print(text) def request_zestfuldata(self): url = self.__ZESTFUL_URL zestful_payload = "{\n \"ingredients\": [\n \"8 Potatoes\",\n \"Onions\",\n \"Carrot\",\n \"8lb Turkey\",\n \"12lb brisket\",\n \"1/2 cup bread crumbs\"\n ]\n}" headers = { 'content-type': "application/json", 'x-rapidapi-key': "85791eb068msha85aad63547a01ap108061jsncf3402c5e5f5", 'x-rapidapi-host': "zestful.p.rapidapi.com" } response = requests.request("POST", url, data=zestful_payload, headers=headers) return json.loads(response.text) # TEST: make the request, and insert returned data to db request = RequestTest() zestful_request = request.request_zestfuldata() request_test = Requests() request_test.insert_zestful_data(zestful_request)
from api import Api import json import pickle from SMBotTimer import SMBotTimer import datetime as dt from datetime import timezone import random import math bot_set = dict() with open('settings.json', 'r') as file: bot_set = json.loads(file.read()) #Insert your private key here, however you like, plain text, encrypted, wallet etc r = Requests("PRIVATE POSTING KEY") player = bot_set["player"] api = Api() bot_timer = SMBotTimer(bot_set["default_sleep"], bot_set["start_time"], bot_set["end_time"]) sm_dict = dict() quest_details = dict() for x in api.settings()["quests"]: quest_details[x["name"]] = x trx = "" while True:
def main(): while (True): opt = func.menu() if opt == "1": #lista passagens # GET /passagem req.handle_list_response(req.send_get(req.URL_GET_PASSAGEM)) func.enter_to_continue() elif opt == "2": #busca de passagens # GET /passagem/{key}/{value} key = input("Digite o campo que deseja pesquisar:\n") value = input("Digite o valor do campo de pesquisa:\n") if (key is not "" and value is not ""): req.handle_list_response( req.send_get(req.URL_GET_PASSAGEM + '/' + key.lower() + '/' + value.lower())) else: print("O campo e o valor de pesquisa devem ser informados") func.enter_to_continue() elif opt == "3": #info passagem # GET /passagem/{id} try: passagem_id = int(input("Digite o ID:\n").strip()) except: print("Um id numérico deve ser digitado!") func.enter_to_continue() continue req.handle_list_response( req.send_get(req.URL_GET_PASSAGEM + '/' + str(passagem_id))) func.enter_to_continue() elif opt == "4": #comprar passagem # POST /passagem/comprar print("==== Digite todos os dados corretamente ====\n") ida_volta = input( "Gostaria de comprar as passagens de ida e volta? S = Sim, N = Não \n" ) if (ida_volta.lower() == 's'): iteracoes = 2 else: iteracoes = 1 for i in range(iteracoes): if i == 0: print("====== Comprando a passagem de ida ====== \n") else: print("====== Comprando a passagem de volta ====== \n") passagem_id = input("Digite o ID da passagem: \n") cartao = input("Digite o número do cartão: \n") parcelas = input("Digite o número de parcelas: \n") n_pessoas = input("Digite o número de passagens desejadas: \n") json = { "id": str(passagem_id), "cartao": str(cartao), "parcelas": str(parcelas), "n_pessoas": str(n_pessoas) } req.handle_list_response( req.send_post(req.URL_POST_PASSAGEM, json=json)) func.enter_to_continue() elif opt == "5": #lista hospedagens #GET /hospedagem req.handle_list_response(req.send_get(req.URL_GET_HOSPEDAGEM)) func.enter_to_continue() elif opt == "6": # GET /hospedagem/{key}/{value} key = input("Digite o campo que deseja pesquisar:\n") value = input("Digite o valor do campo de pesquisa:\n") if (key is not "" and value is not ""): req.handle_list_response( req.send_get(req.URL_GET_HOSPEDAGEM + '/' + key.lower() + '/' + value)) else: print("O campo e o valor de pesquisa devem ser informados") func.enter_to_continue() elif opt == "7": #info hospedagem #GET /hospedagem/{id} try: hospedagem_id = int(input("Digite o ID:\n").strip()) except: print("Um id numérico deve ser digitado!") func.enter_to_continue() continue req.handle_list_response( req.send_get(req.URL_GET_HOSPEDAGEM + '/' + str(hospedagem_id))) func.enter_to_continue() elif opt == "8": #comprar hospedagem #POST /hospedagem/comprar print("==== Digite todos os dados corretamente ====\n") hotel_id = input("Digite o ID do hotel: \n") cartao = input("Digite o número do cartão: \n") parcelas = input("Digite o número de parcelas: \n") n_pessoas = input("Digite o número de quartos desejadas: \n") json = { "id": str(hotel_id), "cartao": str(cartao), "parcelas": str(parcelas), "n_pessoas": str(n_pessoas) } req.handle_list_response( req.send_post(req.URL_POST_HOSPEDAGEM, json=json)) func.enter_to_continue() elif opt == "9": #info compra passagem #GET /compras/passagem/{codigo} id = input("Digite o Código:\n") if (id is not ""): req.handle_list_response( req.send_get(req.URL_GET_COMPRA_PASSAGEM + '/' + id)) else: print("Um código deve ser digitado") func.enter_to_continue() elif opt == "10": #info compra passagem #GET /compras/hospedagem/{codigo} id = input("Digite o Código:\n") if (id is not ""): req.handle_list_response( req.send_get(req.URL_GET_COMPRA_HOSPEDAGEM + '/' + id)) else: print("Um código deve ser digitado") func.enter_to_continue() elif opt == "0": #info compra passagem break else: print("Opção inválida") func.enter_to_continue()
from api import Api import json import pickle from SMBotTimer import SMBotTimer import datetime as dt from datetime import timezone import random import math bot_set = dict() with open('settings.json', 'r') as file: bot_set = json.loads(file.read()) #Insert your private key here, however you like, plain text, encrypted, wallet etc r = Requests("#Private key#") player = bot_set["player"] api = Api() bot_timer = SMBotTimer(bot_set["default_sleep"], bot_set["start_time"], bot_set["end_time"]) sm_dict = dict() quest_details = dict() for x in api.settings()["quests"]: quest_details[x["name"]] = x trx = "" while True:
import sys import os import re import random import ConfigParser from Parameter import Parameter from File import File from Requests import Requests def getconfig(): configs = {} temp = {} conf = ConfigParser.ConfigParser() conf.read('init.conf') for section in conf.sections(): for option in conf.options(section): temp[option] = conf.get(section, option) configs[section] = temp temp = {} return configs configs = getconfig() for i in range(10): p = parameter(configs['request_1']) Requests.post(p)
def __init__(self): self.callbacks = None self._direction = None self._requests = Requests()
class ElevatorLogic(object): """ An incorrect implementation. Can you make it pass all the tests? Fix the methods below to implement the correct logic for elevators. The tests are integrated into `README.md`. To run the tests: $ python -m doctest -v README.md To learn when each method is called, read its docstring. To interact with the world, you can get the current floor from the `current_floor` property of the `callbacks` object, and you can move the elevator by setting the `motor_direction` property. See below for how this is done. """ def __init__(self): self.callbacks = None self._direction = None self._requests = Requests() def on_called(self, floor, direction): """ This is called when somebody presses the up or down button to call the elevator. This could happen at any time, whether or not the elevator is moving. The elevator could be requested at any floor at any time, going in either direction. floor: the floor that the elevator is being called to direction: the direction the caller wants to go, up or down """ self._requests.insert(floor, direction) if self._direction is None: if floor > self.callbacks.current_floor: self._direction = UP elif floor < self.callbacks.current_floor: self._direction = DOWN def on_floor_selected(self, floor): """ This is called when somebody on the elevator chooses a floor. This could happen at any time, whether or not the elevator is moving. Any floor could be requested at any time. floor: the floor that was requested """ if self._direction == UP and floor <= self.callbacks.current_floor: print('select ignored:', floor) return if self._direction == DOWN and floor >= self.callbacks.current_floor: print('select ignored:', floor) return self._requests.insert(floor) if self._direction is None: if floor > self.callbacks.current_floor: self._direction = UP elif floor < self.callbacks.current_floor: self._direction = DOWN def on_floor_changed(self): """ This lets you know that the elevator has moved one floor up or down. You should decide whether or not you want to stop the elevator. """ assert(self.callbacks.motor_direction in (UP, DOWN)) floor = self.callbacks.current_floor maximum = self._requests.is_max(floor, self._direction) member = self._requests.is_member(floor, self._direction) if maximum or member: self.callbacks.motor_direction = None if maximum and not member: self.change_direction() def on_ready(self): """ This is called when the elevator is ready to go. Maybe passengers have embarked and disembarked. The doors are closed, time to actually move, if necessary. """ assert(self.callbacks.motor_direction is None) floor = self.callbacks.current_floor if self._direction: self._requests.delete(floor, self._direction) if self._requests.is_empty(): self._direction = None assert(self.callbacks.motor_direction is None) elif self._requests.is_max(floor, self._direction): self.change_direction() assert(self.callbacks.motor_direction is None) if self._requests.is_member(floor, self._direction): self._requests.delete(floor, self._direction) else: self.callbacks.motor_direction = self._direction else: self.callbacks.motor_direction = self._direction def change_direction(self): assert(self._direction in (UP, DOWN)) if self._direction is UP: self._direction = DOWN elif self._direction is DOWN: self._direction = UP