async def hypesquad(ctx, house): await ctx.message.delete() request = requests.Session() headers = { 'Authorization': token, 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/0.0.305 Chrome/69.0.3497.128 Electron/4.0.8 Safari/537.36' } if house == "bravery": payload = {'house_id': 1} elif house == "brilliance": payload = {'house_id': 2} elif house == "balance": payload = {'house_id': 3} elif house == "random": houses = [1, 2, 3] payload = {'house_id': random.choice(houses)} try: request.post('https://discordapp.com/api/v6/hypesquad/online', headers=headers, json=payload, timeout=10) except Exception as e: print(f"{Fore.RED}[ERROR]: {Fore.YELLOW}{e}" + Fore.RESET)
def accept_tos(self): """ Accept GDPR complient privacy policy """ self.requires_auth() resource = '/account/accept_tos.json' request = Request(user=self.user, password=self.password, token=self.get_token(), cache=self.cache, url=self.url) request.post(resource) return True
def onesignal(mesaj, url): payload = { "app_id": "3865b563-1d29-443d-a8da-7e6b459608c8", "included_segments": ["Active Users"], "contents": { "en": mesaj }, "url": url } request.post("https://onesignal.com/api/v1/notifications", headers=header, data=json.dumps(payload))
def video(request): global omx,qviv global stapwd,setpwd,softPath po = yield from request.post() #print(po) #yield from playv(request) if po['p'] == stapwd: if po['m'] == 'play': omx = OMXPlayer(softPath+'Videos/'+po['d']+'.mp4') tbody= '{"a":"video","b":"play"}' while omx._VOF: yield from asyncio.sleep(0.5) qviv=QIV(softPath+'/'+po['i']) elif po['m'] == 'stop': omx.stop() tbody= '{"a":"video","b":"stop"}' qviv=QIV(softPath+'/'+po['i']) elif po['m'] == 'pause': omx.toggle_pause() tbody= '{"a":"video","b":"pause"}' else: tbody= '{"p":"error"}' print(tbody) return web.Response(headers='' ,body=tbody.encode('utf-8'))
def video(request): global omx #,qviv global stapwd,setpwd,softPath po = yield from request.post() #print(po) if po['p'] == stapwd: if po['m'] == 'play': #print('video play...') omx = OMXPlayer(softPath+'Videos/'+po['d']+'.mp4',softPath+po['i']) tbody= '{"a":"video","b":"play"}' elif po['m'] == 'stop': omx.stop() tbody= '{"a":"video","b":"stop"}' elif po['m'] == 'pause': omx.toggle_pause() tbody= '{"a":"video","b":"pause"}' else: tbody= '{"p":"error"}' print(tbody) return web.Response(headers='' ,body=tbody.encode('utf-8'))
def post_comment(self, message, postid): url = self._get_api_url() + '/{}/comments'.format(postid) access_token = "EAAR3Q7sFWtYBAHKfTuDgRTLLO4DY8SZAjhlpSBRK6tiUXYbm062QsmpXX1gNa4iHoKIa89m5vSJDewC1fdASPnvqEyZA9zslZAYeHBGfl3ROgh2VkmGB6YxEWi09TXASDM4yxkseVb6visaQqtFz7cyura1wg5Pu1f7pC5RwwZDZD" url = url + '?access_token=' + access_token url = url + '&message=' + message response = request.post(url) return response
def setting(request): global shell_ud_t1_set,shell_ud_t2u_set,shell_ud_t2d_set,shell_ud_t3_set global stapwd,setpwd,softPath hhdd=[('Access-Control-Allow-Origin','*')] po = yield from request.post() if po['m'] == 'r': #r+ 以读写模式打开 r只读,w可写,a追加 file_object=open(softPath+'setting.txt','r+') shell_ud_t1_set=int(file_object.readline()) shell_ud_t2u_set=int(file_object.readline()) shell_ud_t2d_set=int(file_object.readline()) shell_ud_t3_set=int(file_object.readline()) file_object.close() tbody= '{"p":"ok","t1":"'+str(shell_ud_t1_set)+'","t2u":"'+str(shell_ud_t2u_set)+'","t2d":"'+str(shell_ud_t2d_set)+'","t3":"'+str(shell_ud_t3_set)+'"}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) if po['m'] == 'w' and po['p'] == setpwd: file_object=open(softPath+'setting.txt','r+') shell_ud_t1_set=int(po['t1']) shell_ud_t2u_set=int(po['t2u']) shell_ud_t2d_set=int(po['t2d']) shell_ud_t3_set=int(po['t3']) file_object.write(str(shell_ud_t1_set)+'\n') file_object.write(str(shell_ud_t2u_set)+'\n') file_object.write(str(shell_ud_t2d_set)+'\n') file_object.write(str(shell_ud_t3_set)+'\n') file_object.close() tbody= '{"p":"ok","w":"ok"}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) tbody= '{"p":"error"}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8'))
def create_exception(self, exception, version_info, project_fname): """ Upload a plugin exception. """ self.requires_auth() resource = '/notifications.json' encoded_file = '' try: file = open(project_fname, 'rb') encoded_file = file.read() except: pass try: exception_info = exception + str(version_info) + encoded_file except: exception_info = 'No exception info (message has encoding problems)' + str( version_info) data = {'type': 'ClientException', 'info': exception_info} request = Request(user=self.user, password=self.password, token=self.get_token(), cache=self.cache, url=self.url) content = request.post(resource, data) return json.loads(content)
def sys_update(request): global softPath hhdd = [('Access-Control-Allow-Origin', '*')] posted = yield from request.post() #print(posted) tbody = '成功' #if posted['tp']=='core': try: upedfile = posted['cfile'] ufilename = upedfile.filename ufilecont = upedfile.file content = ufilecont.read() with open(softPath + ufilename, 'wb') as f: f.write(content) except: tbody = '上传文件打开失败' #解压缩 try: fz = zipfile.ZipFile(softPath + "core.zip", 'r') for file in fz.namelist(): fz.extract(file, softPath) fz.close() except: tbody = '解压失败' return web.Response(headers=hhdd, body=tbody.encode('utf-8'), content_type='application/json')
def create_token(self, user, password): """ Queries the API for a new Token and saves it as self._token. """ request = Request(user=user.encode('utf-8'), password=password.encode('utf-8'), cache=self.cache, url=self.url) content = request.post('/token.json') self.set_token(json.loads(content)) return True
def tableBalance1(): pdfwriter = PyPDF2.PdfFileWriter() for i in range(mon1, mon2 + 1): url = 'http://vip2.kdzwy.com:81/report/report?m=printBalance&reporttype=balance' data = {'dataField': 'name_0#rownum_0#balance_0#prebalance_0#name_1#rownum_1#balance_1#prebalance_1', 'columnTitle': '%E8%B5%84%E4%BA%A7#%E8%A1%8C%E6%AC%A1#%E6%9C%9F%E6%9C%AB%E6%95%B0#%E5%B9%B4%E5%88%9D%E6%95%B0#%E8%B4%9F%E5%80%BA%E5%92%8C%E6%89%80%E6%9C%89%E8%80%85%EF%BC%88%E6%88%96%E8%82%A1%E4%B8%9C%EF%BC%89%E6%9D%83%E7%9B%8A#%E8%A1%8C%E6%AC%A1#%E6%9C%9F%E6%9C%AB%E6%95%B0#%E5%B9%B4%E5%88%9D%E6%95%B0', 'showParams': '%5Bobject%20Object%5D', 'marginLeft': 0, 'marginTop': 0, 'eachPageVou': 2, 'pagePrint': 1, 'js_disPrintMaker': 0, 'js_printAttachments': 0, 'js_printCover': 0, 'isSummary': 0, 'level': '', 'dcSummary': 0, 'notShowZero': 0, 'showSameItem': 0, 'showPrintDate': 0, 'showPage': 0, 'printDate': '2018-07-15', 'showQtyPrice': 0, 'showCur': 0, 'pageSize': '', 'pageDirection': 'x', 'pageRotationNumber': '', 'pageZWY': 0, 'fontSize': 9} if i < 10: # 月份数字调整 a = '%%E8%%B5%%84%%E4%%BA%%A7%%E8%%B4%%9F%%E5%%80%%BA%%E8%%A1%%A8#%s0%s' % (year, i) q = "%s0%s" % (year, i) else: a = '%%E8%%B5%%84%%E4%%BA%%A7%%E8%%B4%%9F%%E5%%80%%BA%%E8%%A1%%A8#%s%s' % (year, i) q = "%s%s" % (year, i) data['period'] = q data['sheetName'] = a loginPage = request.post(url, data=data, headers=header, cookies=cookies) # 获取页面 file = "D:\\pachong\\账无忧、易代账\\账无忧\\本次资产负债表\\资产负债表" + str(i) + "月.pdf" fp = open(file, "w+b") # 打开一个文本文件 fp.write(loginPage.content) # 写入数据i fp.close() # 关闭文件.#抓取资产负债表(1-12月) # ——————建立pdfreader,先读出来,放在pdfreader里,方便后续操作。。 readFile = file pdfreader = PyPDF2.PdfFileReader(readFile) page1 = pdfreader.getPage(0) # ——————建立pdfwriter,先写进到writer里(可以add多页),再导入目标文件。 # ——————add多个页面到writer pdfwriter.addPage(page1) # print('抓取资产负债表成功!') return pdfwriter
def create_database(self): """ Create a database. """ self.requires_auth() resource = '/databases.json' request = Request(user=self.user, password=self.password, token=self.get_token(), cache=self.cache, url=self.url) data = {} content = request.post(resource, data) return json.loads(content)
def exportTotal(): # 抓取总账默认1-12月 url = 'http://vip2.kdzwy.com:81/gl/general?m=printExport&random=1531657739118' data = {'dataField': 'yearPeriod#exp#gdebit#gcredit#dcType#gbalance', 'columnTitle': '%E6%9C%9F%E9%97%B4#%E6%91%98%E8%A6%81#%E5%80%9F%E6%96%B9#%E8%B4%B7%E6%96%B9#%E6%96%B9%E5%90%91#%E4%BD%99%E9%A2%9D', 'dataField_page': 'number#name#yearPeriod#exp#gdebit#gcredit#dcType#gbalance', 'columnTitle_page': '%E7%A7%91%E7%9B%AE%E7%BC%96%E7%A0%81#%E7%A7%91%E7%9B%AE%E5%90%8D%E7%A7%B0#%E6%9C%9F%E9%97%B4#%E6%91%98%E8%A6%81#%E5%80%9F%E6%96%B9#%E8%B4%B7%E6%96%B9#%E6%96%B9%E5%90%91#%E4%BD%99%E9%A2%9D', 'sheetName': '%E6%80%BB%E8%B4%A6#' + str(year) + '%E5%B9%B4%E7%AC%AC' + str( mon1) + '%E6%9C%9F%20%E8%87%B3%20' + str(year) + '%E5%B9%B4%E7%AC%AC' + str(mon2) + '%E6%9C%9F', 'op': 1, 'taodaUrl': '/gl/general?m=notePrintGeneral', 'billType': 'General', 'fromPeriod': str(year) + str(mon1), # ————总账时间起始 'toPeriod': str(year) + str(mon2), # ————总账时间终止 'reportitem': '', 'fromAccountId': '', 'toAccountId': '', 'fromLevel': 1, 'toLevel': 1, 'includeItem': 0, 'currency': 'RMB', 'showParams': '%5Bobject%20Object%5D', 'marginLeft': 0, 'marginTop': 0, 'eachPageVou': 2, 'pagePrint': 1, 'js_disPrintMaker': 0, 'js_printAttachments': 0, 'js_printCover': 0, 'isSummary': 0, 'level': 1, 'dcSummary': 0, 'notShowZero': 0, 'showSameItem': 0, 'showPrintDate': 0, 'showPage': 0, 'printDate': '2018-07-15', 'showQtyPrice': 0, 'showCur': 0, 'pageSize:'',' 'pageDirection': 'x', 'pageRotationNumber': '', 'pageZWY': 0, 'fontSize': 9} loginPage = request.post(url, data=data, headers=header, cookies=cookies) # 获取页面 zp = open(mkpath + "\\总账.pdf", "w+b") # 打开一个文本文件 zp.write(loginPage.content) # 写入数据i zp.close() # ————————数总账 readFile = mkpath + "\\总账.pdf" pdfreader = PyPDF2.PdfFileReader(readFile) nums = pdfreader.getNumPages() os.rename(mkpath + "\\总账.pdf", mkpath + "\\总 %s页.pdf" % nums) RGzz='抓取总账成功共%s页!' % nums return RGzz
def exportDetail(): # 抓取明细账,默认1-12月 url = 'http://vip2.kdzwy.com:81/gl/general?m=printExportDetail' data = {'dataField': 'ymd#voucherNo#remark#debit#credit#dcType#balance', 'columnTitle': '%E6%97%A5%E6%9C%9F#%E5%87%AD%E8%AF%81%E5%AD%97%E5%8F%B7#%E6%91%98%E8%A6%81#%E5%80%9F%E6%96%B9#%E8%B4%B7%E6%96%B9#%E6%96%B9%E5%90%91#%E4%BD%99%E9%A2%9D', 'sheetName': '%E6%98%8E%E7%BB%86%E8%B4%A6#' + str(year) + '%E5%B9%B4%E7%AC%AC' + str( mon1) + '%E6%9C%9F%20%E8%87%B3%20' + str(year) + '%E5%B9%B4%E7%AC%AC' + str(mon2) + '%E6%9C%9F', 'op': 2, 'taodaUrl': '/gl/general?m=notePrintDetail', 'billType': 'GeneralDetail', 'fromPeriod': str(year) + str(mon1), # ——————起明细账时间 'toPeriod': str(year) + str(mon2), # ——————终明细账时间 'accountNum': 1001, 'number': 1001, 'accountId': 566904462545066, 'includeItem': 1, 'currency': 'RMB', 'showOppositeAcct': 0, 'marginLeft': 0, 'marginTop': 0, 'eachPageVou': 2, 'pagePrint': 1, 'js_disPrintMaker': 0, 'js_printAttachments': 0, 'js_printCover': 0, 'isSummary': 0, 'level': 1, 'dcSummary': 0, 'notShowZero': 0, 'showSameItem': 0, 'showPrintDate': 0, 'showPage': 0, 'printDate': '2018-07-16', 'showQtyPrice': 0, 'showCur': 0, 'pageSize': '', 'pageDirection': 'y', 'pageRotationNumber': '', 'pageZWY': 0, 'fontSize': 9} loginPage = request.post(url, data=data, headers=header, cookies=cookies) # 获取页面 zp = open(mkpath + "\\明细账.pdf", "w+b") # 打开一个文本文件 zp.write(loginPage.content) # 写入数据i zp.close() # ————数明细账 readFile = mkpath + "\\明细账.pdf" pdfreader = PyPDF2.PdfFileReader(readFile) nums = pdfreader.getNumPages() RGmx='抓取明细账成功!共%s页' % nums os.rename(mkpath + "\\明细账.pdf", mkpath + "\\明细账 %s页.pdf" % nums) return RGmx
async def from_aiohttp_request(cls, request: Request): self = cls(proto=(request.scheme.upper() + "/%s.%s" % (request.version.major, request.version.minor)), host=request.host, method=request.method, uri=request.raw_path, args=request.post(), remote_ip=request.transport.get_extra_info('peername')[0], headers=request.headers, body_file=await request.read(), cookies=request.cookies) self.aiohttp_request = request return self
def __call__(self, request): kw = None if self._has_var_kw_arg or self._has_named_kw_arg or self._required_kw_args: if request.method == 'POST': if not request.content_type: return web.HTTPBadRequest('Missing content-type') ct = request.content_type.lower() if ct.startswith('application/json'): params = yield from request.json() if not isinstance(params, dict): return web.HTTPBadRequest('Json body must be object') kw = params elif ct.startswith('application/x-www-form-urlencoded' ) or ct.startswith('multipart/form-data'): params = yield from request.post() kw = dict(**params) else: return web.HTTPBadRequest('Unsupported content-type: %s' % request.content_type) if request.method == 'GET': qs = request.query_string if qs: kw = dict() for k, v in parse.parse_qs(qs, True).items(): kw[k] = v[0] if kw is None: kw = dict(**request.match_info) else: if not self._has_var_kw_arg and self._named_kw_args: copy = dict() for name in self._named_kw_args: if name in kw: copy[name] = kw[name] kw = copy for k, v in request.metch_info.items(): if k in kw: logging.warning( 'Duplicate arg name in named arg and kw args %s:' % k) kw[k] = v if self._has_request_arg: kw['request'] = request if self._required_kw_args: for name in self._required_kw_args: if not name in kw: return web.HTTPBadRequest('Missing argument: %s' % name) logging.info('call with args: %s' % str(kw)) try: r = yield from self._func(**kw) return r except APIError as e: return dict(error=e.error, data=e.data, message=e.message)
def sendMail(amount, lastPrice): r = request.post( "https://api.mailgun.net/v3/sandboxb0290be0c6374214b94158e8986a61b2.mailgun.org/messages", auth=("api", "key-7f1ccf639b43e107cda773f9eec84ea5"), data={"from": "Eagle <*****@*****.**>", "to": config['myName'] + " <" + config['myMail'] + ">", "subject": "Crypto finance report", "text": "Good evening Mitsara,\r\n\r\nIf you sell everything you have right now with the bid price you would have in total " + str(amount) + "BTC. \r\nThis equals to " + str(amount * lastPrice) + " euro. \r\n\r\nHave a beautiful day,\r\nEagle"}) if (r.status_code) == 200: return True else: return False
def recoginze_captcha(self, image_url): recognize_url = image_url formdata = {} with open('captcha.png', 'rb') as fp: data = fp.read() pic = b64decode(data) formdata['pic'] = pic appcode = '' headers = {"Content-Type": '', 'Authorization': 'APPCODE' + appcode} response = request.post(recognize_url, data=formdata, headers=headers) result = response.json() code = result['result']['code'] return code
def requests_base_use(): # 1.get 请求 request.get(url) # 2.get带参数 :自动转码 params = {"kw": 2} requests.get(url, params=params) # 3.post请求 request.post(url) # 4.带参数 :自动转码 formdata = {"kw": 2} request.post(url, data=formdata) # 5.ssl --ca的证书 忽略证书认证 requests.get(url, verfy=False) # 6.proxy proxy = {"http": "IP:port"} requests.get(url, proxies=proxy) # 8.webauth auth = ("username", "pwd") requests.get(url, auth=auth) # 7.cookie --session #71.创建session 还是为了保存cookie session = requests.session() #7.2 发送登录 -- cookie session.post(url) #7.3 session.post(data_url)
def create_graphic(self, name, symbol): """ Upload a symbol. """ self.requires_auth() resource = '/graphics.json' file = open(symbol, "rb") encoded_file = file.read() data = { 'graphic': json.dumps({ 'name' : name, }), 'file': encoded_file } request = Request(user=self.user, password=self.password, token=self.get_token(), cache=self.cache, url=self.url) content = request.post(resource, data) return json.loads(content)
def create_table(self, db_name, table, overwrite_table, columns, srid, geometry_type, provider, pkey=None, geom_column=None, geom_column_index=None): """ Create a new table overwrite_table = <bool>, drop table if it exists columns = [ { 'name': '<NAME>', 'type': '<TYPE>', 'length': <LENGTH>, 'precision': <PRECISION> }, ... ] srid = 'EPSG:<SRID>' geometry_type = 'POINT' | 'MULTIPOINT' | 'LINESTRING' | 'MULTILINESTRING' | 'POLYGON' | 'MULTIPOLYGON' provider = '<QGIS PROVIDER NAME>' pkey, geom_column, geom_column_index = primary key and geometry column and index for PostGIS provider """ self.requires_auth() resource = '/databases/%s/tables.json' % (db_name) data = { 'table': json.dumps({ 'overwrite': overwrite_table, 'name': table, 'columns': [], 'srid': srid, 'geometry_type': geometry_type }), 'provider': provider } data['table']['columns'] = columns if pkey is not None: data['table']['pkey'] = pkey if geom_column is not None: data['table']['geom_column'] = geom_column if geom_column_index is not None: data['table']['geom_column_index'] = geom_column_index request = Request(user=self.user, password=self.password, token=self.get_token(), cache=self.cache, url=self.url) content = request.post(resource, data) return json.loads(content)
def readEver(songId): url = 'http://music.163.com/weapi/v1/resource/comments/R_SO_4_' + str(songId) + '/?csrf_token=' headers = {'Cookie': 'appver=1.5.0.75771;', 'Referer': 'http://music.163.com/'} text = {'username': '******', 'password': '******', 'rememberLogin': '******'} modulus = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7' nonce = '0CoJUm6Qyw8W8jud' pubKey = '010001' text = json.dumps(text) secKey = createSecretKey(16) encText = aesEncrypt(aesEncrypt(text, nonce), secKey) encSecKey = rsaEncrypt(secKey, pubKey, modulus) data = {'params': encText, 'encSecKey': encSecKey} req = request.post(url, headers=headers, data=data) total = req.json()['total'] if int(total) > 10000: print(songId, total) else: pass
def setting(request): global shell_ud_t1_set, shell_ud_t2u_set, shell_ud_t2d_set, shell_ud_t3_set global shell_sdu, shell_sdd global stapwd, setpwd, softPath, seled_cai hhdd = [('Access-Control-Allow-Origin', '*')] tbody = '{"p":"error"}' po = yield from request.post() if po['m'] == 'l' and po['p'] == setpwd: tbody = '{"p":"ok"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) if po['m'] == 'w' and po['p'] == setpwd: shell_ud_t1_set = po['t1'] shell_ud_t2u_set = po['t2u'] shell_ud_t2d_set = po['t2d'] shell_ud_t3_set = po['t3'] shell_sdu = po['sdu'] shell_sdd = po['sdd'] stapwd = po['stapwd'] kconfig.set("yp", "shell_ud_t1_set", str(shell_ud_t1_set)) kconfig.set("yp", "shell_ud_t2u_set", str(shell_ud_t2u_set)) kconfig.set("yp", "shell_ud_t2d_set", str(shell_ud_t2d_set)) kconfig.set("yp", "shell_ud_t3_set", str(shell_ud_t3_set)) kconfig.set("yp", "shell_sdu", str(shell_sdu)) kconfig.set("yp", "shell_sdd", str(shell_sdd)) kconfig.set("yp", "stapwd", stapwd) kconfig.write(open(softPath + "setting.ini", "w")) tbody = '{"p":"ok","w":"ok"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) if po['m'] == 'addcai': if po['s'] == 'true': seled_cai.remove(po['c']) #print(seled_cai) tbody = '{"p":"dec"}' else: seled_cai.append(po['c']) #print(seled_cai) tbody = '{"p":"add"}' #tbody= '{"p":"error"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8'))
def setting(request): global shell_ud_t1_set,shell_ud_t2u_set,shell_ud_t2d_set,shell_ud_t3_set global shell_sdu,shell_sdd global stapwd,setpwd,softPath,seled_cai hhdd=[('Access-Control-Allow-Origin','*')] tbody= '{"p":"error"}' po = yield from request.post() if po['m'] == 'l' and po['p'] == setpwd: tbody= '{"p":"ok"}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) if po['m'] == 'w' and po['p'] == setpwd: shell_ud_t1_set=po['t1'] shell_ud_t2u_set=po['t2u'] shell_ud_t2d_set=po['t2d'] shell_ud_t3_set=po['t3'] shell_sdu=po['sdu'] shell_sdd=po['sdd'] stapwd=po['stapwd'] kconfig.set("yp","shell_ud_t1_set",str(shell_ud_t1_set)) kconfig.set("yp","shell_ud_t2u_set",str(shell_ud_t2u_set)) kconfig.set("yp","shell_ud_t2d_set",str(shell_ud_t2d_set)) kconfig.set("yp","shell_ud_t3_set",str(shell_ud_t3_set)) kconfig.set("yp","shell_sdu",str(shell_sdu)) kconfig.set("yp","shell_sdd",str(shell_sdd)) kconfig.set("yp","stapwd",stapwd) kconfig.write(open(softPath+"setting.ini","w")) tbody= '{"p":"ok","w":"ok"}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) if po['m'] == 'addcai': if po['s'] == 'true': seled_cai.remove(po['c']) #print(seled_cai) tbody= '{"p":"dec"}' else: seled_cai.append(po['c']) #print(seled_cai) tbody= '{"p":"add"}' #tbody= '{"p":"error"}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8'))
def create_map(self, name, mapfile, config): """ Create a new map and return it. """ # name = name.decode('utf-8') self.requires_auth() resource = '/maps.json' file = open(mapfile, "rb") encoded_file = file.read() data = { 'map': json.dumps({ 'name' : name, 'config': config }), 'file': encoded_file } request = Request(user=self.user, password=self.password, token=self.get_token(), cache=self.cache, url=self.url) content = request.post(resource, data) return json.loads(content)
def check_login(self, version_info): self.requires_auth() resource = '/notifications.json' data = {'type': 'Login', 'info': version_info} request = Request(user=self.user, password=self.password, token=self.get_token(), cache=self.cache, url=self.url) # request = Request(user=self.user.encode('utf-8'), # password=self.password.encode('utf-8'), # token=self.get_token(), # cache=self.cache, # url=self.url) content = request.post(resource, data) login_info = json.loads(content) if 'clouddb' not in login_info: login_info['clouddb'] = True return login_info
def video(request): global omx global stapwd, setpwd, softPath po = yield from request.post() if 1: #po['p'] == stapwd: if po['m'] == 'play': #print('video play...') omx = OMXPlayer(softPath + 'Videos/' + po['d'] + '.mp4', softPath + po['i']) tbody = '{"a":"video","b":"play"}' elif po['m'] == 'stop': omx.stop() tbody = '{"a":"video","b":"stop"}' elif po['m'] == 'pause': omx.toggle_pause() tbody = '{"a":"video","b":"pause"}' else: tbody = '{"p":"error"}' print(tbody) return web.Response(headers='', body=tbody.encode('utf-8'))
def return_sta(request): global eTimer1,eIntval1,eTimer2,eIntval2,sta_shell,sta_onoff,watchdog global shell_up_down,shell_ud_t1,shell_ud_t2u,shell_ud_t2d,shell_ud_t3 global stapwd,setpwd,softPath,tempeture_1 hhdd=[('Access-Control-Allow-Origin','*')] po = yield from request.post() if po['p'] == stapwd: if po['m'] == 'login': sta_shell=0 sta_onoff=0 tbody= '{"p":"ok"}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) elif po['m'] == 'sta': watchdog=0 tbody= '{"shell_sta":'+str(sta_shell)+',"running_sta":'+str(sta_onoff)+',"tmp1":'+str(tempeture_1)+'}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) elif po['m'] == 'gpioon': delaytime=po['t'] if po['d']== 'fm': eTimer1=True eIntval1=int(time.time())+int(delaytime) print('eTimer1 1 start') sta_shell=1 sta_onoff=1 GPIO.output(io_zq, 0) GPIO.output(io_jr, 0) tbody= '{"a":"zq+jr","b":"on"}' elif po['d']== 'fs': GPIO.output(io_bw, 0) tbody= '{"a":"bw","b":"on"}' elif po['d']== 'sk': GPIO.output(io_sk, 0) tbody= '{"a":"sk","b":"on"}' elif po['d']== 'ms': GPIO.output(io_zq, 0) GPIO.output(io_jr, 0) tbody= '{"a":"ms","b":"on"}' print(tbody) return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) elif po['m'] == 'gpiooff': if po['d']== 'fm': sta_onoff=0 GPIO.output(io_zq, 1) GPIO.output(io_jr, 1) tbody= '{"a":"zq+jr","b":"off"}' elif po['d']== 'fs': GPIO.output(io_bw, 1) tbody= '{"a":"bw","b":"off"}' elif po['d']== 'sk': GPIO.output(io_sk, 1) tbody= '{"a":"sk","b":"off"}' elif po['d']== 'ms': GPIO.output(io_zq, 1) GPIO.output(io_jr, 1) tbody= '{"a":"ms","b":"off"}' print(tbody) return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) elif po['m'] == 'shell': GPIO.output(moto_1_f, 1) GPIO.output(moto_1_r, 1) shell_ud_t1=shell_ud_t1_set shell_ud_t3=shell_ud_t3_set if po['d']== 'up' and sta_shell!=1: GPIO.output(moto_1_r, 0) p.ChangeDutyCycle(40) shell_ud_t2u=shell_ud_t2u_set shell_ud_t2d=-1 shell_up_down=0 sta_shell=1 tbody= '{"a":"shell","b":"up"}' elif po['d']== 'dw' and sta_shell!=1: GPIO.output(moto_1_f, 0) p.ChangeDutyCycle(40) shell_ud_t2u=-1 shell_ud_t2d=shell_ud_t2d_set shell_up_down=2 sta_shell=1 tbody= '{"a":"shell","b":"dw"}' elif sta_shell==1: sta_shell=2 p.ChangeDutyCycle(0) tbody= '{"a":"shell","b":"stop"}' print(tbody) return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) elif po['m'] == 'pump2': GPIO.output(moto_2_f, 0) GPIO.output(moto_2_r, 1) p2.ChangeDutyCycle(int(po['spd'])) tbody= '{"a":"pump2","b":"'+po['spd']+'"}' print(tbody) return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) else: tbody= '{"p":"error"}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8'))
#coding=utf-8 import urllib.request import urllib.parse class HttpRequest(object): def __init__(self, url): self.url = url def get(self, param): params = urllib.parse.urlencode(param) url = self.url + '?%s' % params with urllib.request.urlopen(url) as response: result = response.read().decode('utf-8') return result def post(self, param): data = urllib.parse.urlencode(param) data = data.encode() with urllib.request.urlopen(self.url, data) as response: result = response.read().decode('utf-8') return result if __name__ == '__main__': request = HttpRequest('https://www.baidu.com/') s = request.post('') print(s)
def return_sta(request): global eTimer1, eIntval1, watchdog, running_sta global shell_up_down, sta_shell, guolupower, settemp, timediff global stapwd, softPath, tempeture_1, tempeture_2, ttim, t global ttfinck, worktime, seled_cai global shell_ud_t1_set, shell_ud_t2u_set, shell_ud_t2d_set, shell_ud_t3_set global spdu, spdd, ver, sn, toreboot hhdd = [('Access-Control-Allow-Origin', '*'), ('Content-Type', 'application/json')] po = yield from request.post() #if po['p'] == stapwd: if 1: if po['m'] == 'sta': watchdog = 0 tbody = '{"shell_sta":' + str(sta_shell) tbody += ',"guolupower":' + str(guolupower) tbody += ',"settemp":' + str(settemp) tbody += ',"timediff":' + str(timediff) tbody += ',"running_sta":' + str(running_sta) tbody += ',"ttfinck":' + str(ttfinck) tbody += ',"wt":' + str(int(time.time() - worktime)) tbody += ',"cai":"' + (seled_cai) + '"' tbody += ',"tmp1":' + str(tempeture_1) + '}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'sel_cai': seled_cai = po['cai'] tbody = '{"sel_cai":"ok"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'addtime': watchdog = 0 #print('old stop at'+str(eIntval1)) eIntval1 += int(po['d']) #print('shall stop at '+str(eIntval1)) #tbody= '{"addtime":'+str(eIntval1-int(time.time()))+'}' tbody = '{"addtime":"ok"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'settemp': settemp = 0 running_sta = po['d'] if po['ttmp'] == 'xh': ttmp = b'\x02\x06\x10\x01\x03\xD4\xDC\x56' settemp = 98 if po['ttmp'] == 'zh': ttmp = b'\x02\x06\x10\x01\x04\x60\xDE\x11' settemp = 112 if po['ttmp'] == 'dh': ttmp = b'\x02\x06\x10\x01\x05\x14\xDF\xA6' settemp = 130 try: ser = serial.Serial("/dev/ttyUSB0", parity=serial.PARITY_ODD, timeout=1) ser.write(ttmp) recv = ser.read(8) #print(recv) ser.close() except e: pass tbody = '{"settemp":"' + po['ttmp'] + '"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'gpioon': if po['d'] == 'dy': guolupower = 1 GPIO.output(io_dy, 0) tbody = '{"dy":"on"}' print(tbody) return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'gpiooff': if po['d'] == 'dy': guolupower = 0 GPIO.output(io_dy, 1) tbody = '{"dy":"off"}' elif po['d'] == 'zq': if sta_shell == 1: t.cancel() p.ChangeDutyCycle(0) sta_shell = 0 GPIO.output(moto_1_r, 1) GPIO.output(moto_1_f, 1) eIntval1 = time.time() GPIO.output(io_zq, 1) tbody = '{"zq":"off"}' print(tbody) return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'zq_on': running_sta = 1 eTimer1 = True eIntval1 = int(time.time()) + int(po['dltime']) ttim = time.time() GPIO.output(io_zq, 0) print('zq eTimer1 start') tbody = '{"zq":"1",' + '"timediff":"' + str(timediff) + '"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'shell': tbody = '{"a":"shell","b":"noaction"}' if sta_shell == 1: ttfin() tbody = '{"shell":"0"}' else: if po['d'] == 'up': shell_up() tbody = '{"shell":"1"}' elif po['d'] == 'dw': shell_dw() #running_sta=1 #eIntval1=int(time.time())+int(po['dltime']) tbody = '{"shell":"1"}' elif po['d'] == 'dwon': shell_dw() running_sta = 1 eIntval1 = int(time.time()) + int(po['dltime']) tbody = '{"shell":"1"}' print(tbody) ttim = time.time() return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'gset': tbody = '{"get":"set",' tbody += '"t1":"' + str(shell_ud_t1_set) + '",' tbody += '"t2u":"' + str(shell_ud_t2u_set) + '",' tbody += '"t2d":"' + str(shell_ud_t2d_set) + '",' tbody += '"t3":"' + str(shell_ud_t3_set) + '",' tbody += '"spdu":"' + str(spdu) + '",' tbody += '"spdd":"' + str(spdd) + '",' tbody += '"ver":"' + ver + '",' tbody += '"sn":"' + str(sn) + '"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'wset': shell_ud_t1_set = int(po['t1']) shell_ud_t2u_set = int(po['t2u']) shell_ud_t2d_set = int(po['t2d']) shell_ud_t3_set = int(po['t3']) spdu = int(po['spdu']) spdd = int(po['spdd']) sn = po['sn'] kconfig.set("gh", "shell_ud_t1_set", po['t1']) kconfig.set("gh", "shell_ud_t2u_set", po['t2u']) kconfig.set("gh", "shell_ud_t2d_set", po['t2d']) kconfig.set("gh", "shell_ud_t3_set", po['t3']) kconfig.set("gh", "spdu", po['spdu']) kconfig.set("gh", "spdd", po['spdd']) kconfig.set("gh", "sn", po['sn']) kconfig.write(open(softPath + "setting.ini", "w")) tbody = '{"p":"ok","w":"ok"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'reboot': system('sudo reboot') elif po['m'] == 'upgrade': #tbody= 'Update Successful' tbody = '{"p":"升级成功,重启中"}' #if po['tp']=='core': try: upedfile = po['cfile'] ufilename = upedfile.filename ufilecont = upedfile.file content = ufilecont.read() with open(softPath + ufilename, 'wb') as f: f.write(content) except: tbody = '{"p":"Open File error"}' #解压缩 try: #fz = zipfile.ZipFile(softPath+"core.zip",'r') print(softPath + ufilename) fz = zipfile.ZipFile(softPath + ufilename, 'r') for file in fz.namelist(): fz.extract(file, softPath) fz.close() print('update done, to reboot') toreboot = 1 return web.Response(headers=hhdd, body=tbody.encode('utf-8')) except: tbody = '{"p":"decompression error"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) else: tbody = '{"p":"error"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8'))
# Base URL being accessed url = 'http://httpin.org/post' # Dictionary of query paameters (if any) parms = { 'name1':'value1', 'name2':'value2' } # Extra headers headers = { 'User-agent ' : 'none/ofyoubusiness', 'Spam' : 'Eggs' } resp = request.post(url, data =parms, headers =headers) # Decode text returned by the request text = resp.text --------------------------------------------------------------------------- --------------------------------------------------------------------------- # If we use request lib post a HEAD ask, and get some information form Http headers import request resp = requests.head('http://www.python.org/index.html') status = resp.status_code last_modified =resp
def postStatusUpdate(self, fbPost): print("Sending post to facebook") params = {'message': fbPost.message, 'access_token': self.access_token} url = "https://graph.facebook.com/%s/feed?" % fbPost.postTo request = HttpRequest() request.post(url, params)
import urllib.request user = '******' message = 'Hello World!' r = request.post("http://akipress.org", data={ 'user': user, 'massage': massage })
elif (mode == DOWNLOAD_REPORT_FILE): request = get_credentials() if (request != False): ret = view_report(request, report_id) if (not ret['bad_cred']): file_id = -1 if (len(ret['files']) > 0): print('files:') for k in ret['files'].keys(): print(' ' + k + ': ' + ret['files'][k]["name"]) print(' encrypted: ' + str(ret['files'][k]["encrypted"])) file_id = input("specify file id: ") filename = ret['files'][file_id]['url'] #~ print(filename) download_report_file(request, report_id, file_id, filename) else: print('no files') else: mode = AUTH_FAILURE else: mode = AUTH_FAILURE elif (mode == UPLOAD_FDA): print('upload fda:') request = get_credentials() ret = request.post(BASE_URL + 'fda/upload-fda/', files={'fda': open('fda.py', 'rb')}) print(ret.text) if (mode == AUTH_FAILURE): print("error: bad login credentials")
def setting(request): global shell_ud_t1_set, shell_ud_t2u_set, shell_ud_t2d_set, shell_ud_t3_set global ver, sn, spdu, spdd global stapwd, setpwd, softPath, seled_cai, seled_cai_cn hhdd = [('Access-Control-Allow-Origin', '*')] tbody = '{"p":"error"}' po = yield from request.post() if po['m'] == 'l' and po['p'] == setpwd: tbody = '{"p":"ok"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) if po['m'] == 'get': try: ip = po['ip'] except: ip = '' tbody = '{"p":"ok",' tbody += '"ver":"' + ver + '",' tbody += '"t1":"' + str(shell_ud_t1_set) + '",' tbody += '"t2u":"' + str(shell_ud_t2u_set) + '",' tbody += '"t2d":"' + str(shell_ud_t2d_set) + '",' tbody += '"t3":"' + str(shell_ud_t3_set) + '",' tbody += '"spdu":"' + str(spdu) + '",' tbody += '"spdd":"' + str(spdd) + '",' tbody += '"ip":"' + str(ip) + '",' tbody += '"sn":"' + str(sn) + '",' tbody += '"stapwd":"' + str(stapwd) + '"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) if po['m'] == 'w' and po['p'] == setpwd: shell_ud_t1_set = int(po['t1']) shell_ud_t2u_set = int(po['t2u']) shell_ud_t2d_set = int(po['t2d']) shell_ud_t3_set = int(po['t3']) spdu = int(po['spdu']) spdd = int(po['spdd']) sn = po['sn'] stapwd = po['stapwd'] kconfig.set("gh", "shell_ud_t1_set", po['t1']) kconfig.set("gh", "shell_ud_t2u_set", po['t2u']) kconfig.set("gh", "shell_ud_t2d_set", po['t2d']) kconfig.set("gh", "shell_ud_t3_set", po['t3']) kconfig.set("gh", "spdu", po['spdu']) kconfig.set("gh", "spdd", po['spdd']) kconfig.set("gh", "sn", po['sn']) kconfig.set("gh", "stapwd", stapwd) kconfig.write(open(softPath + "setting.ini", "w")) tbody = '{"p":"ok","w":"ok"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) if po['m'] == 'addcai': scai = po['c'] scai_cn = po['cn'] if po['s'] == 'true': seled_cai.remove(scai) seled_cai_cn.remove(scai_cn) tbody = '{"p":"dec"}' else: seled_cai.append(scai) seled_cai_cn.append(scai_cn) tbody = '{"p":"add"}' if po['m'] == 'get_added_cai': tbody = '~' for i in seled_cai: tbody = tbody + i + ';' tbody = str(tbody) if po['m'] == 'reboot': system('sudo reboot') return web.Response(headers=hhdd, body=tbody.encode('utf-8'))
def return_sta(request): global eTimer1, eIntval1, self_ctrl, watchdog, running_sta global shell_up_down, sta_shell, guolupower, settemp, timediff global stapwd, setpwd, softPath, tempeture_1, tempeture_2, ttim, t global ttfinck, worktime hhdd = [('Access-Control-Allow-Origin', '*')] po = yield from request.post() #if po['p'] == stapwd: if 1: if po['m'] == 'login': sta_shell = 0 self_ctrl = 0 tbody = '{"p":"ok"}' if po['p'] != stapwd: tbody = '{"p":"error"}' if po['p'] == '3568': worktime = time.time() tbody = '{"p":"tcls"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'sta': watchdog = 0 self_ctrl = 0 tbody = '{"shell_sta":' + str(sta_shell) tbody += ',"guolupower":' + guolupower tbody += ',"settemp":' + settemp tbody += ',"timediff":' + str(timediff) tbody += ',"running_sta":' + running_sta tbody += ',"ttfinck":' + str(ttfinck) tbody += ',"wt":' + str(int(time.time() - worktime)) tbody += ',"tmp1":' + str(tempeture_1) + '}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'addtime': watchdog = 0 #print('old stop at'+str(eIntval1)) eIntval1 += int(po['d']) #print('shall stop at '+str(eIntval1)) tbody = '{"addtime":' + str(eIntval1 - int(time.time())) + '}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'settemp': settemp = '0' running_sta = po['d'] if po['ttmp'] == 'xh': ttmp = b'\x02\x06\x10\x01\x03\xD4\xDC\x56' settemp = '98' if po['ttmp'] == 'zh': ttmp = b'\x02\x06\x10\x01\x04\x60\xDE\x11' settemp = '112' if po['ttmp'] == 'dh': ttmp = b'\x02\x06\x10\x01\x05\x14\xDF\xA6' settemp = '130' ser = serial.Serial("/dev/ttyUSB0", parity=serial.PARITY_ODD, timeout=1) ser.write(ttmp) recv = ser.read(8) #print(recv) ser.close() tbody = '{"settemp":"' + po['ttmp'] + '"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'gpioon': if po['d'] == 'dy': guolupower = '1' GPIO.output(io_dy, 0) tbody = '{"a":"dy","b":"on"}' if po['d'] == 'zq': running_sta = '1' delaytime = po['t'] eTimer1 = True eIntval1 = int(time.time()) + int(delaytime) ttim = time.time() print('eTimer1 start') GPIO.output(io_zq, 0) tbody = '{"a":"zq","b":"on"}' print(tbody) return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'gpiooff': if po['d'] == 'all': GPIO.output(io_zq, 1) eTimer1 = False running_sta = '0' tbody = '{"a":"all","b":"off"}' elif po['d'] == 'dy': guolupower = '0' GPIO.output(io_dy, 1) tbody = '{"a":"dy","b":"off"}' elif po['d'] == 'zq': running_sta = '0' GPIO.output(io_zq, 1) tbody = '{"a":"zq","b":"off"}' print(tbody) return web.Response(headers=hhdd, body=tbody.encode('utf-8')) elif po['m'] == 'shell': tbody = '{"a":"shell","b":"noaction"}' if po['d'] == 'up': try: t.cancel() except: pass t = threading.Timer(shell_ud_t1_set / 1000, tt2) GPIO.output(moto_1_r, 0) GPIO.output(moto_1_f, 1) p.ChangeDutyCycle(100) t.start() shell_up_down = 0 sta_shell = 1 tbody = '{"a":"shell","b":"up"}' elif po['d'] == 'dw': try: t.cancel() except: pass t = threading.Timer(shell_ud_t1_set / 1000, tt2) GPIO.output(moto_1_r, 1) GPIO.output(moto_1_f, 0) p.ChangeDutyCycle(100) t.start() shell_up_down = 2 sta_shell = 1 tbody = '{"a":"shell","b":"dw"}' elif sta_shell == 1: ttfin() tbody = '{"a":"shell","b":"stop"}' print(tbody) ttim = time.time() return web.Response(headers=hhdd, body=tbody.encode('utf-8')) else: tbody = '{"p":"error"}' return web.Response(headers=hhdd, body=tbody.encode('utf-8'))
# -*- coding = utf-8 -*- """ @time:2020-07-06 19:12:26 @project:apiauto2020 @file:sessionHandler.py @author:Jiang ChengLong """ from urllib import request import requests # 通过session,可以不需要手动去拿cookie信息,很有用 session = requests.sessions.session() # 发送登录请求 login_res = session.post(url='http://*****/***/*/*/member/login', data={ "mobilephone": "133***33331", "pwd": "12****" }) # 发送充值请求 login_res = request.post(url='http://*****/***/*/*/member/rech', data={ "mobilephone": "133***33331", "pwd": "12****" })
def return_sta(request): global eTimer1,eIntval1,eTimer2,eIntval2,sta_onoff,watchdog global shell_up_down,sta_shell,huixiqi,omx global stapwd,setpwd,softPath,tempeture_1,ttim,t hhdd=[('Access-Control-Allow-Origin','*')] po = yield from request.post() if po['p'] == stapwd: if po['m'] == 'login': sta_shell=0 sta_onoff=0 tbody= '{"p":"ok"}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) elif po['m'] == 'sta': watchdog=0 ttb='{"shell_sta":'+str(sta_shell) ttb+=',"running_sta":'+str(sta_onoff) ttb+=',"tmp1":'+str(tempeture_1) if hasattr(omx,'sta_video')==False: sta_video=0 else: sta_video=omx.sta_video ttb+=',"sta_video":'+str(sta_video) ttb+='}' tbody= ttb return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) elif po['m'] == 'addtime': watchdog=0 #print('old stop at'+str(eIntval1)) eIntval1+=int(po['d']) #print('shall stop at '+str(eIntval1)) tbody= '{"addtime":'+po['d']+'}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) elif po['m'] == 'gpioon': delaytime=po['t'] if po['d']== 'fm': eTimer1=True eIntval1=int(time.time())+int(delaytime) ttim=time.time() print('eTimer1 start') #sta_shell=1 sta_onoff=1 GPIO.output(io_zq, 0) GPIO.output(io_jr, 0) tbody= '{"a":"zq+jr","b":"on"}' elif po['d']== 'ms': GPIO.output(io_zq, 0) GPIO.output(io_jr, 0) sta_onoff=1 tbody= '{"a":"ms","b":"on"}' elif po['d']== 'hx': GPIO.output(io_hx, 0) tbody= '{"a":"hx","b":"on"}' elif po['d']== 'zq': GPIO.output(io_zq, 0) tbody= '{"a":"zq","b":"on"}' eIntval1=int(time.time())+int(delaytime) ttim=time.time() eTimer1=True print('eTimer1 start zp') elif po['d']== 'bw': GPIO.output(io_bw, 0) tbody= '{"a":"bw","b":"on"}' elif po['d']== 'sk': GPIO.output(io_sk, 0) GPIO.output(io_hx, 0) huixiqi=-1 tbody= '{"a":"sk","b":"on"}' print(tbody) return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) elif po['m'] == 'gpiooff': if po['d']== 'fm': sta_onoff=0 GPIO.output(io_zq, 1) GPIO.output(io_jr, 1) eTimer1=False huixiqi=200 GPIO.output(io_hx, 0) print('huixiqi on fm') tbody= '{"a":"zq+jr","b":"off"}' elif po['d']== 'ms': GPIO.output(io_zq, 1) GPIO.output(io_jr, 1) sta_onoff=0 tbody= '{"a":"ms","b":"off"}' elif po['d']== 'hx': GPIO.output(io_hx, 1) #print('io_hx off') tbody= '{"a":"hx","b":"off"}' elif po['d']== 'zq': sta_onoff=0 GPIO.output(io_zq, 1) eTimer1=False #print('eTimer1 off zq') tbody= '{"a":"zq","b":"off"}' elif po['d']== 'bw': GPIO.output(io_bw, 1) tbody= '{"a":"bw","b":"off"}' elif po['d']== 'sk': GPIO.output(io_sk, 1) huixiqi=200 GPIO.output(io_hx, 0) print('huixiqi on sk 30s') tbody= '{"a":"sk","b":"off"}' elif po['d']== 'all': GPIO.output(io_zq, 1) GPIO.output(io_bw, 1) GPIO.output(io_sk, 1) GPIO.output(io_jr, 1) GPIO.output(io_hx, 1) GPIO.output(io_ss, 1) #huixiqi=200 tbody= '{"a":"all","b":"off"}' print(tbody) return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) elif po['m'] == 'shell': if po['d']== 'up' and sta_shell!=1: t = threading.Timer(shell_ud_t1_set/1000, tt2) GPIO.output(moto_1_r, 0) GPIO.output(moto_1_f, 1) p.ChangeDutyCycle(100) t.start() shell_up_down=0 sta_shell=1 tbody= '{"a":"shell","b":"up"}' elif po['d']== 'dw' and sta_shell!=1: t = threading.Timer(shell_ud_t1_set/1000, tt2) GPIO.output(moto_1_r, 1) GPIO.output(moto_1_f, 0) p.ChangeDutyCycle(100) t.start() shell_up_down=2 sta_shell=1 tbody= '{"a":"shell","b":"dw"}' elif sta_shell==1: #sta_shell=1 #t.cancel() #p.ChangeDutyCycle(0) tbody= '{"a":"shell","b":"stop"}' print(tbody) ttim=time.time() return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) elif po['m'] == 'pump2': GPIO.output(moto_2_f, 0) GPIO.output(moto_2_r, 1) #p2.ChangeDutyCycle(int(po['spd'])) if int(po['spd'])==100: GPIO.output(io_ss, 0) else: GPIO.output(io_ss, 1) tbody= '{"a":"pump2","b":"'+po['spd']+'"}' print(tbody) return web.Response(headers=hhdd ,body=tbody.encode('utf-8')) else: tbody= '{"p":"error"}' return web.Response(headers=hhdd ,body=tbody.encode('utf-8'))