def Signature(orderid,reportid): api_url = HOST + "/api/Report/Signature" header = {'content-type': 'application/octet-stream', # 头信息 'Authorization': config.get_token(), 'userinfo': USERINFO} from ProtobufPy.ReportRequestPb_pb2 import ReportRequestPb rr_body = ReportRequestPb() """对象入参赋值""" rr_body.orderID = orderid rr_body.reportID = reportid rr_body.abnormalFlag = '0' # rr_body.imagingFinding = '影像所见测试内容' rr_body.imagingFinding = FakerData.fake.paragraph() print(rr_body.imagingFinding) # rr_body.imagingDiagnosis = '影像诊断测试内容' rr_body.imagingDiagnosis = FakerData.fake.paragraph() rr_body.resultAssistantID = '42819E01-C077-4DB5-8B09-ACBC00A5343E' rr_body.resultAssistantName = '贾苗' rr_body.resultPrincipalID = '42819E01-C077-4DB5-8B09-ACBC00A5343E' rr_body.resultPrincipalName = '贾苗' rr_body.isCheckedWriteAndAudit = 1 from ProtobufPy.OrderReportRequestPb_pb2 import OrderReportRequestPb orr_body = OrderReportRequestPb() orr_body.report.CopyFrom(rr_body) orr_body = orr_body.SerializeToString() # 将对象转化成字符串 print(orr_body) """模拟客户端发出请求""" with request(method='POST', url=api_url, data=orr_body, headers=header,timeout=5, ) as ar_res: """解析返回结果""" res_str = ar_res.content # 获取返回的正文
def yaks(user, location): """Return raw response data for messages at location using user""" params = [("accuracy", user.location.accuracy), ("lat", location.latitude), ("long", location.longitude), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "yaks", params)
def get_message(user, message_id): """Return raw response data for a message (ID: message_id) using user""" params = [("accuracy", user.location.accuracy), ("messageID", message_id), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "getMessage", params)
def place_order(env, location_id, lines_qty, stock_file, template_file): get_stock(env, stock_file) contracts_list = get_contracts_list(env=env, location_id=location_id) service_contract = next(contracts_list)[0:-1] order = generate_template(env=env, location_id=location_id, contract=service_contract, template_file=template_file, stock_file=stock_file, lines_qty=lines_qty) endpoint = f"https://co-winter-{env}.tom.takeoff.com/order" send_order = requests.post(url=endpoint, json=order, headers={"X-Token": get_token(env)}) if send_order.status_code != 200: response_content = send_order.content response_content_dict = ast.literal_eval( response_content.decode("utf-8")) if "details-from-3dparty-service" in response_content_dict: print(response_content_dict['details-from-3dparty-service'] ["message"]) print(f"error sending order {send_order.status_code}") else: order_id = order["order-id"] print(f"{order_id} successfully placed!") print("waiting for split") time.sleep(1) print(f"trying to split {order_id}") split_order(env=env, order_id=order_id) return order_id return None
def save_basecamp(user, name, location): """Return raw response data from saving a basecamp""" params = [("token", get_token()), ("userID", user.user_id)] data = [("bcLat", location.latitude), ("bcLong", location.longitude), ("bcName", name), ("bcPeekId", 0)] return _send("POST", settings.BASECAMP_ENDPOINT, "saveBasecamp", params, data)
def request(options: dict, url): x = generateRandomID() config.set_uniqueid(x) get_url = API_URL + url headers = { 'content-type': 'application/json', 'X-AppVersion': config.get_app_version(), 'X-UniqueId': config.unique_id, 'X-Location': config.get_location(), 'authorization': 'Bearer ' + config.get_token() } print(headers) headers.update(options.get('headers', {})) if options['method'] == 'GET': r = requests.get(get_url, headers=headers, params=options.get('params', '')) elif options['method'] == 'POST': r = requests.post(get_url, headers=headers, json=options['body']) elif options['method'] == 'DELETE': r = requests.delete(get_url, headers=headers) else: return {'success': False, 'message': 'Bad parameters, please try again'}, 401 ret_dict = {'status_code' : r.status_code} ret_dict.update(r.json()) return ret_dict
def get_basecamps(user): """Return raw response data for all basecamps of user""" params = [("lat", user.location.latitude), ("long", user.location.longitude), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.BASECAMP_ENDPOINT, "getBasecamps", params)
def get_area_tops(user): """Return raw response data for top Yaks in area""" params = [("lat", user.location.latitude), ("long", user.location.longitude), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "getAreaTops", params)
def get_my_recent_replies(user): """Return raw response data for recent replies of user""" params = [("accuracy", user.location.accuracy), ("lat", user.location.latitude), ("long", user.location.longitude), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "getMyRecentReplies", params)
def downvote_message(user, message_id, basecamp=0): """Return raw response data from downvoting a message (ID: message_id) using user (optionally at basecamp)""" params = [("accuracy", user.location.accuracy), ("bc", int(basecamp)), ("messageID", message_id), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "downvoteMessage", params)
def like_comment(user, comment_id, basecamp=0): """Return raw response data from upvoting a comment (ID: comment_id) using user (optionally at basecamp)""" params = [("accuracy", user.location.accuracy), ("bc", int(basecamp)), ("commentID", comment_id), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "likeComment", params)
def register_user(user): """Return raw response data from registering user""" params = [("accuracy", user.location.accuracy), ("deviceID", generate_id(dashes=False, upper=True)), ("lat", user.location.latitude), ("long", user.location.longitude), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "registerUser", params)
def contact_us(user, message, category, email): """Return raw response data from contacting Yik Yak with message in particular category using user with specified email""" params = [("token", get_token()), ("userID", user.user_id)] data = [("category", category), ("email", email), ("message", message)] return _send("POST", settings.YIKYAK_ENDPOINT, "contactUs", params, data)
def log_event(user, event_type): """Return raw response data from logging an app event of type event_type using user""" params = [("accuracy", user.location.accuracy), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] data = [("eventType", event_type), ("lat", user.location.latitude), ("long", user.location.longitude)] return _send("POST", settings.YIKYAK_ENDPOINT, "logEvent", params, data)
def split_order(env, order_id): url = f"https://co-winter-{env}.tom.takeoff.com/order/split/{order_id}" split = requests.put(url=url, headers={"X-Token": get_token(env)}) if split.status_code != 200: response_content = split.content response_content_dict = ast.literal_eval( response_content.decode("utf-8")) print(f"split failed {split.status_code}") else: print("order split!")
def get_peek_messages(user, peek_id): """Return raw response data for messages at peek location (ID: peek_id) using user""" params = [("accuracy", user.location.accuracy), ("lat", user.location.latitude), ("long", user.location.longitude), ("peekID", peek_id), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "getPeekMessages", params)
def hot(user, location, basecamp=0): """Return raw response data for top messages in location/basecamp using user""" if basecamp: location = user.basecamp_location params = [("accuracy", user.location.accuracy), ("bc", int(basecamp)), ("lat", location.latitude), ("long", location.longitude), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "hot", params)
def main(): logging.basicConfig(format='[%(asctime)s][%(levelname)s]:%(message)s', level=logging.WARNING, datefmt='%d.%m.%Y %H:%M:%S') token = config.get_token() db_url = config.get_db_url() bot_db = dbconnect.BotDB(db_url) thesisbot = ThesisBot(token, bot_db) thesisbot.run()
def submit_peek_message(user, message, peek_id, handle=None, btp=0): """Return raw response data from submitting a peek message with an optional handle at peek location with ID peek_id using user (optionally with parameter bypassedThreatPopup as btp)""" params = [("token", get_token()), ("userID", user.user_id)] data = [("bypassedThreatPopup", int(btp)), ("lat", user.location.latitude), ("long", user.location.longitude), ("message", message), ("peekID", peek_id)] if handle: data += [("hndl", handle)] return _send("POST", settings.YIKYAK_ENDPOINT, "submitPeekMessage", params, data)
def get_scs(env, location_id): with open("contracts_list.txt", "r+") as scs: scs.truncate(0) url = get_scs_url(env=env, location_id=location_id) data = (requests.get(url=url, headers={"X-Token": get_token(env)})).json() contracts = [] for record in data: contracts.append(record["service-window-start"]) for contract in contracts: dt = zulu.parse(contract) usable_contract = f"{(dt.isoformat())[0:-6]}" + "Z" with open("contracts_list.txt", "a+") as contracts_list_file: contracts_list_file.write(f"{usable_contract}\n")
def get_comments(user, message_id, basecamp=0): """Return raw response data for all comments on a message (ID: message_id) using user (optionally at basecamp)""" if basecamp: location = user.basecamp_location else: location = user.location params = [("accuracy", user.location.accuracy), ("bc", int(basecamp)), ("lat", location.latitude), ("long", location.longitude), ("messageID", message_id), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "getComments", params)
def report_message(user, message_id, reason, basecamp=0): """Return raw response data from reporting a message (ID: message_id) for a specified reason using user (optionally at basecamp)""" if basecamp: location = user.basecamp_location else: location = user.location params = [("accuracy", user.location.accuracy), ("bc", int(basecamp)), ("lat", location.latitude), ("long", location.longitude), ("messageID", message_id), ("reason", reason), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "reportMessage", params)
def send_message(user, message, handle=None, btp=0, basecamp=0): """Return raw response data from sending a message with an optional handle using user (optionally at basecamp and optionally with parameter bypassedThreatPopup as btp)""" if basecamp: location = user.basecamp_location else: location = user.location params = [("bc", int(basecamp)), ("token", get_token()), ("userID", user.user_id)] data = [("bypassedThreatPopup", int(btp)), ("lat", location.latitude), ("long", location.longitude), ("message", message)] if handle: data += [("hndl", handle)] return _send("POST", settings.YIKYAK_ENDPOINT, "sendMessage", params, data)
def delete_comment(user, comment_id, message_id, basecamp=0): """Return raw response data from deleting a comment (ID: comment_id) belonging to a message (ID: message_id) with user (optionally at basecamp)""" if basecamp: location = user.basecamp_location else: location = user.location params = [("accuracy", user.location.accuracy), ("bc", int(basecamp)), ("commentID", comment_id), ("lat", location.latitude), ("long", location.longitude), ("messageID", message_id), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] return _send("GET", settings.YIKYAK_ENDPOINT, "deleteComment", params)
def send_req(nam, path, meth = 'GET', body = '', isCorrect = lambda c: c == 200): url = config.get_url(nam) cn = mk_conn(url) fullUrl = '%s/api/v3/%s' % (url, path) cn.request(meth, fullUrl, body, { 'PRIVATE-TOKEN': config.get_token(nam), 'Content-Type': 'application/json' }) rsp = cn.getresponse() ret = rsp.read() assert isCorrect(rsp.status), '''Server has returned an error URL: %s Status: %d Body: %s''' % (fullUrl, rsp.status, ret) return json.loads(ret)
def send_req(nam, path, meth='GET', body='', isCorrect=lambda c: c == 200): url = config.get_url(nam) cn = mk_conn(url) fullUrl = '%s/api/v3/%s' % (url, path) cn.request(meth, fullUrl, body, { 'PRIVATE-TOKEN': config.get_token(nam), 'Content-Type': 'application/json' }) rsp = cn.getresponse() ret = rsp.read() assert isCorrect(rsp.status), '''Server has returned an error URL: %s Status: %d Body: %s''' % (fullUrl, rsp.status, ret) return json.loads(ret)
def post_comment(user, comment, message_id, btp=0, basecamp=0): """Return raw response data from posting a comment belonging to message (ID: message_id) using user (optionally at basecamp and optionally with parameter bypassedThreatPopup as btp)""" if basecamp: location = user.basecamp_location else: location = user.location params = [("accuracy", user.location.accuracy), ("bc", int(basecamp)), ("token", get_token()), ("userID", user.user_id), ("userLat", user.location.latitude), ("userLong", user.location.longitude)] data = [("bypassedThreatPopup", int(btp)), ("comment", comment), ("lat", location.latitude), ("long", location.longitude), ("messageID", message_id)] return _send("POST", settings.YIKYAK_ENDPOINT, "postComment", params, data)
def PageList(): api_url = HOST + "/api/ReportList/PageList" #RIS接口地址 header = {'content-type': 'application/octet-stream', # 头信息 'Authorization': config.get_token(), 'userinfo': USERINFO} #导入protobuf入参文件 from ProtobufPy.ViOrderReportRequestPb_pb2 import ViOrderReportRequestPb ar_body = ViOrderReportRequestPb() """对象入参赋值""" ar_body.observationEndDate = '2021-05-08 00:00:00|2021-05-08 23:59:59' ar_body.resultStatus = '2090' ar_body.currentPage = 1 ar_body.pageSize = 20 ar_body = ar_body.SerializeToString() # 将对象转化成字符串 """模拟客户端发出请求""" with request(method='POST', url=api_url, data=ar_body, headers=header,timeout=5, ) as ar_res: """解析返回结果""" # print(ar_res.content) # print(ar_res.status_code) from ProtobufPy.PageResponsePb_pb2 import PageResponsePb ar_data = PageResponsePb() # 创建返回参数pb对象 res_str = ar_res.content # 获取返回的正文 ar_data.ParseFromString(res_str) # 从返回正文解析(第一层解析) # print(ar_data) # print("---------------------") from google.protobuf.json_format import MessageToJson # 用于第二层解析特殊的类型 from ProtobufPy.ReportListResponsePb_pb2 import ReportListResponsePb # 导入返回参数中的相关pb ar_json = MessageToJson(ar_data) # print(ar_data) ar_dict = json.loads(ar_json.encode('utf-8').decode("unicode_escape"), strict=False) # 先处理unicode成中文,然后转化成字典 # print(ar_dict) # 获取检查列表信息 orderlist = ar_dict['data'][0]['orderReport'] print(orderlist,type(orderlist)) for a in orderlist: print(a,type(a)) orderid = a['orderID'] reportid = Loading(orderid) Signature(orderid,reportid) print('orderid为{0},reportid为{1}的检查签名成功'.format(orderid,reportid))
def Loading(orderid): api_url = HOST + "/api/Report/Loading" header = {'content-type': 'application/octet-stream', # 头信息 'Authorization': config.get_token(), 'userinfo': USERINFO} from ProtobufPy.ReportRequestPb_pb2 import ReportRequestPb rr_body = ReportRequestPb() """对象入参赋值""" rr_body.orderID = orderid from ProtobufPy.OrderReportRequestPb_pb2 import OrderReportRequestPb orr_body = OrderReportRequestPb() orr_body.report.CopyFrom(rr_body) orr_body = orr_body.SerializeToString() # 将对象转化成字符串 """模拟客户端发出请求""" with request(method='POST', url=api_url, data=orr_body, headers=header,timeout=5, ) as ar_res: """解析返回结果""" from ProtobufPy.PageResponsePb_pb2 import PageResponsePb ar_data = PageResponsePb() # 创建返回参数pb对象 res_str = ar_res.content # 获取返回的正文 ar_data.ParseFromString(res_str) # print(ar_data) from google.protobuf.json_format import MessageToJson # 用于第二层解析特殊的类型 from ProtobufPy.ReportWriteListResponsePb_pb2 import ReportWriteListResponsePb ar_json = MessageToJson(ar_data) # print(ar_data) ar_dict = json.loads(ar_json.encode('utf-8').decode("unicode_escape"), strict=False) # 先处理unicode成中文,然后转化成字典 # print(ar_dict) report = ar_dict['data'][0]['report'] # print(report,type(report)) # print(report['reportID']) return report['reportID']
import discord import config import traceback import sys from discord.ext import commands from discord import Status ########################### # Setup Bot Configuration # ########################### # Create a config if it does not yet exist config.initialize() TOKEN = config.get_token() COMMAND_PREFIX = config.get_command_prefix() bot = commands.Bot(command_prefix=COMMAND_PREFIX) # Define bot extensions extensions = ['cogs.chat', 'cogs.timein', 'cogs.help'] # Update members in configuration async def update_members(): for user in bot.get_all_members(): if not config.user_in_config(user) and user.id != bot.user.id: config.add_user(user) ###############
def __init__(self): self.tk = get_token() self.cl = EvernoteClient(token=self.tk, sandbox=True) self.ns = self.cl.get_note_store()
message.channel, "I have PM'd you the list of places") elif command == "commands" and config.check_command(command): tmp = await client.send_message(message.author, commands.list_commands()) tmp2 = await client.send_message( message.channel, "I have PM'd you the list of commands") else: try: args = message.content.split(' ', 1)[1] except: args = "" if config.check_command(command): tmp = await client.send_message( message.channel, commands.get_response(message, command, args)) else: tmp = await client.send_message( message.channel, commands.get_unsupported_msg(command)) async def check_triggers(message): for response in triggers.get_response(message): tmp = await client.send_message(message.channel, response) return print(config.get_token()) client.run(config.get_token())
if profile.running(): await ctx.channel.send(f'`{key}` is running') else: await ctx.channel.send(f'`{key}` has stopped') @bot.command() async def kill(ctx, key: str) -> None: if ctx.channel.id not in config.get_channels(): await ctx.channel.send('Not authorised to run in this channel!') return profile = config.get_profile(key) if profile is None: await ctx.channel.send(f'Unknown profile `{key}`') return if not profile.running(): await ctx.channel.send(f'Profile `{key}` is already not running') return profile.kill() await ctx.channel.send(f'Killed `{key}`!') if not config.load_config(): print('No config file found! New one created @ config.json. Please fill it out and run me again!') sys.exit(1) bot.run(config.get_token())
async def on_socket_closed(): client.run(config.get_token())
if message.channel.id in wpi.pogo.filterChannels: await wpi.pogo.filter(message, client) if message == None: return if message.content.startswith('$') and \ message.author.id != client.user.id: command = message.content[len("$"):].split()[0].lower() if command in wpi.core.functions: wpi.util.increment_command(message) await client.send_typing(message.channel) await wpi.core.functions[command](message, client) else: await client.send_message(message.channel, "That is not a valid command!") @client.event async def on_member_join(member): string = "Welcome to **" + member.server.name + "**, " + member.mention + "!\n" + "Please make sure to read <#221767295171559425>!" await client.send_message(member.server.default_channel, string) #if not member.server in wpi.util.commands: #wpi.util.add_server(member.server.id) #if wpi.util.commands[member.server.id]["welcome_enabled"]: #await client.send_message(member.server.default_channel, wpi.util.commands[member.server.id]["welcome_m @client.event async def on_socket_closed(): client.run(config.get_token()) client.run(config.get_token())
def error_handler(bot, update, error): if is_authorized(update): err_msg = 'Update "{}" caused error "{}"'.format(update, error) send_message(bot, update, err_msg) def help_cmd(bot, update): send_message(bot, update, get_help_text()) if __name__ == '__main__': logging.basicConfig( level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) updater = telegram.Updater(token=config.get_token()) bc.dispatcher = updater.dispatcher PLUGINS = [ cancel, clear, emojis, gimme, insult, lights, quote, random_fact, shell_exec, sms, snap, ]