How to use post_result method in avocado

Best Python code snippet using avocado_python

publisher.py

Source:publisher.py Github

copy

Full Screen

1import requests2from sqlalchemy import text3import sqlalchemy4from urllib.parse import quote_plus as urlquote5import db.base_engine as dao6import pandas as pd7token_return = requests.get("http://www.nbippc.cn/Retrieval/getDiAccesstoken?appid=1051&appkey=1051")8token = token_return.json()['result']9def post_detail(pid):10 url = 'http://114.251.8.193/api/patent/detail/catalog'11 params = {12 "pid": pid,13 "lang": "cn",14 "scope": "read_cn",15 "client_id": "5d8f767eac110007108d0e0a77f83ea8",16 "access_token": token17 }18 result_json = requests.post(url, data=params)19 return result_json20def post_express2(express):21 url = 'http://114.251.8.193/api/patent/search/expression2?lang=cn&scope=read_cn&client_id=5d8f767eac110007108d0e0a77f83ea8&access_token=%s&express=%s&page=1&page_row=10' % (22 token, express)23 # params = {24 # "lang": "cn",25 # "scope": "read_cn",26 # "client_id": "5d8f767eac110007108d0e0a77f83ea8",27 # "access_token": token,28 # "express": express.encode('GBK'),29 # "page": "1",30 # "page_row": "10"31 # }32 result = requests.post(url)33 return result34def post_express(express):35 url = 'http://114.251.8.193/api/patent/search/expression?lang=cn&scope=read_tw&client_id=5d8f767eac110007108d0e0a77f83ea8&access_token=%s&express=%s&page=1&page_row=10' % (36 token, express)37 result = requests.post(url)38 return result39def do_express2():40 with dao.engine187.connect() as conn:41 sql = text("SELECT DISTINCT apn_f FROM Lvjiaan.dbo.a_ex3 WHERE pid IS NULL ")42 result = conn.execute(sql).fetchall()43 for row in result:44 apn = row[0]45 print(apn)46 post_result = post_express2('(申请号=(%s))' % (apn))47 if post_result.json()['total'] != '':48 pid = post_result.json()['context']['records'][0]['pid']49 pno = post_result.json()['context']['records'][0]['pno']50 sql = text("UPDATE Lvjiaan.dbo.a_ex3 SET pno=:pno,pid=:pid WHERE apn_f=:apn_f")51 conn.execute(sql, {"pno": str(pno), "pid": pid, "apn_f": str(apn)})52def post_law(pid):53 url = "http://114.251.8.193/api/patent/detail/law"54 params = {55 "pid": pid,56 "lang": "cn",57 "scope": "read_cn",58 "client_id": "5d8f767eac110007108d0e0a77f83ea8",59 "access_token": token60 }61 post_result = requests.post(url, data=params)62 return post_result63def do_law():64 with dao.engine187.connect() as conn:65 sql = text("SELECT pid FROM Lvjiaan.dbo.a_ex2 WHERE pid IS NOT NULL AND grant_date IS NULL")66 result = conn.execute(sql).fetchall()67 for row in result:68 pid = row[0]69 print(pid)70 try:71 result = post_law(pid)72 records = result.json()['context']['records'][0]73 df = pd.DataFrame(records)74 df['pid'] = pid75 df.to_sql("a_ct_law", con=dao.engine187, index=False, if_exists='append')76 except Exception:77 pass78def post_patent_list_solr(apn):79 url = 'http://api.sti.gov.cn/stiservice/sendMessage'80 token = requests.get(81 "http://api.sti.gov.cn/oauth/token?username=jeecg&grant_type=saml_auth&client_id=client_3&client_secret=s4DWmpkNm8HS").json()[82 'access_token']83 params = {84 'app_id': 'cfdc9a74030a41659cd43b887baf4800',85 'app_code': 'PatentList',86 'client_id': '1001',87 'client_secret': '1024',88 'server_name': 'PatentList',89 'params': '{"applyNum":"%s"}' % (apn),90 'method': 'POST'91 }92 headers = {93 'Authorization': 'bearer ' + token94 }95 post_result = requests.post(url, data=params, headers=headers)96 return post_result97def do_solr():98 with dao.engine187.connect() as conn:99 sql = text(100 "SELECT DISTINCT apn_f FROM Lvjiaan.dbo.a_ex2 WHERE patent_name IS NULL AND apn_f IS NOT NULL AND PATENT_name is null")101 result = conn.execute(sql).fetchall()102 for row in result:103 apn = row[0]104 print(apn)105 post_result = post_patent_list_solr(apn)106 if post_result.json()['body']['data']['totalItemCount'] != 0:107 patentee = ''108 patentname = post_result.json()['body']['data']['data'][0]['patentname']109 statuscode = post_result.json()['body']['data']['data'][0]['statuscode']110 grantdate = post_result.json()['body']['data']['data'][0]['grantdate']111 try:112 patentee = post_result.json()['body']['data']['data'][0]['patentee']113 except Exception:114 pass115 # pno = post_result.json()['body']['data']['data'][0]['publicnum']116 sql = text(117 "UPDATE Lvjiaan.dbo.a_ex2 SET patent_name=:patent_name,patentee=:patentee,grant_date=:grant_date,status_code=:status_code WHERE apn_f=:apn_f")118 conn.execute(sql, {"patent_name": str(patentname), "patentee": patentee, "grant_date": grantdate,119 "status_code": statuscode, "apn_f": str(apn)})120def do_solr_ex4():121 with dao.engine187.connect() as conn:122 sql = text(123 "SELECT DISTINCT apn_f FROM Lvjiaan.dbo.a_ex4 WHERE patent_name IS NULL AND apn_f IS NOT NULL AND PATENT_name is null")124 result = conn.execute(sql).fetchall()125 for row in result:126 apn = row[0]127 print(apn)128 post_result = post_patent_list_solr(apn)129 if post_result.json()['body']['data']['totalItemCount'] != 0:130 patentname = post_result.json()['body']['data']['data'][0]['patentname']131 applyname = post_result.json()['body']['data']['data'][0]['applypersonname']132 applydate = post_result.json()['body']['data']['data'][0]['applydate']133 # pno = post_result.json()['body']['data']['data'][0]['publicnum']134 sql = text(135 "UPDATE Lvjiaan.dbo.a_ex4 SET patent_name=:patent_name,apply_name=:apply_name,apply_date=:apply_date WHERE apn_f=:apn_f")136 conn.execute(sql, {"patent_name": str(patentname), "apply_name": applyname, "apply_date": applydate,137 "apn_f": str(apn)})138def do_detail():139 with dao.engine187.connect() as conn:140 sql = text("SELECT pid FROM Lvjiaan.dbo.a_ex3 WHERE pid IS NOT NULL AND patent_name IS NULL")141 result = conn.execute(sql).fetchall()142 for row in result:143 pid = row[0]144 print(pid)145 category_json = post_detail(pid).json()['context']['records'][0]['catalogPatent']146 print(category_json)147 patentname = category_json['tio']148 apply_name = category_json['apo']149 apply_date = category_json['ad']150 sql = text(151 "UPDATE Lvjiaan.dbo.a_ex3 SET patent_name=:patent_name,apply_name=:apply_name,apply_date=:apply_date WHERE pid=:pid")152 conn.execute(sql, {"patent_name": str(patentname), "apply_name": apply_name,153 "apply_date": apply_date, "pid": str(pid)})154def do_detail2():155 with dao.engine187.connect() as conn:156 sql = text("SELECT pid FROM Lvjiaan.dbo.a_ex1 WHERE pid IS NOT NULL AND patent_name IS NULL")157 result = conn.execute(sql).fetchall()158 for row in result:159 pid = row[0]160 print(pid)161 category_json = post_detail(pid).json()162 sql = text(163 "UPDATE Lvjiaan.dbo.a_ex1 SET json=:json WHERE pid=:pid")164 conn.execute(sql, {"json": str(category_json), "pid": str(pid)})165def do_express():166 with dao.engine187.connect() as conn:167 sql = text("SELECT DISTINCT applynum FROM Lvjiaan.dbo.a_1027 WHERE applynum IS NOT NULL AND tio is NULL")168 result = conn.execute(sql).fetchall()169 for row in result:170 apn = row[0]171 print(apn)172 post_result = post_express('(公布号=(%s))' % (apn.replace('/', '\/')))173 try:174 if post_result.json()['total'] == '':175 continue176 list_records = post_result.json()['context']['records']177 tio = ''178 aso = ''179 lssc = ''180 apo = ''181 ad = ''182 print(list_records)183 for record in list_records:184 try:185 if tio == '':186 tio = record['tio']187 except Exception:188 pass189 try:190 if aso == '':191 aso = record['aso']192 except Exception:193 pass194 try:195 if lssc == '':196 lssc = record['lsscn']197 except Exception:198 pass199 try:200 if apo == '':201 apo = record['apo']202 except Exception:203 pass204 try:205 if ad == '':206 ad = record['ad'].split(' ')[0].replace('/', '')207 except Exception:208 pass209 sql = text(210 "UPDATE Lvjiaan.dbo.a_1027 SET tio=:tio,aso=:aso,lssc=:lssc,apo=:apo,ad=:ad WHERE applynum=:applynum")211 conn.execute(sql,212 {"tio": str(tio), "aso": aso, "apo": apo, "lssc": lssc, "ad": ad, "applynum": str(apn)})213 except Exception:214 pass215 # break216if __name__ == '__main__':217 do_express()218 # do_solr_ex4()219 # do_express2()220 # do_detail()...

Full Screen

Full Screen

extra_field_updates_tests.py

Source:extra_field_updates_tests.py Github

copy

Full Screen

1import time2from django.test import TestCase3from tests.lists.models import Item4from tests.lists.tests.helper import set_up_helper5from django.utils.timezone import now6class ListExtraFieldUpdateTest(TestCase):7 def setUp(self):8 set_up_helper()9 self.pre_result = list(10 Item.objects.filter(list=1).order_by("order").11 values_list("id", "updated_by", "order_changed_count", "order"))12 #time.sleep(0.1)13 def _assert_helper(self, changed):14 post_result = list(15 Item.objects.order_by("list", "id").16 values_list("id", "updated_by", "order_changed_count", "list", "order"))17 # created should stay the same18 self.assertEqual([(r[0], r[1]) for r in self.pre_result],19 [(r[0], r[1]) for r in post_result])20 # Updated should change, but only on those that are changed21 for i in range(len(post_result)): # Feels bad to check in loop22 if (post_result[i][3], post_result[i][4]) in changed:23 self.assertNotEqual(24 (self.pre_result[i][0], self.pre_result[i][2]),25 (post_result[i][0], post_result[i][2]))26 else:27 self.assertEqual(28 (self.pre_result[i][0], self.pre_result[i][2]),29 (post_result[i][0], post_result[i][2]))30 def test_change_order_first_to_second(self):31 item = Item.objects.filter(list=1, order=0).first()32 item.printit = True33 item.order = 134 item.save()35 post_result = list(36 Item.objects.filter(list=1).order_by("order").37 values_list("id", "updated_by", "order_changed_count", "order"))38 #print("test_change_order_first_to_second")39 #print(post_result)40 self.assertEqual(post_result,41 [(2, 'a', 1, 0),42 (1, 'a', 1, 1),43 (3, '', 0, 2),44 (4, '', 0, 3),45 (5, '', 0, 4)46 ])47 def test_change_order_multiple_changes(self):48 item = Item.objects.filter(list=1, order=0).first()49 item.order = 150 item.save()51 item = Item.objects.filter(list=1, order=1).first()52 item.order = 253 item.save()54 item = Item.objects.filter(list=1, order=2).first()55 item.order = 356 item.save()57 post_result = list(58 Item.objects.filter(list=1).order_by("order").59 values_list("id", "updated_by", "order_changed_count", "order"))60 #print("test_change_order_multiple_changes")61 #print(post_result)62 self.assertEqual(post_result,63 [(2, 'a', 1, 0),64 (3, 'a', 1, 1),65 (4, 'a', 1, 2),66 (1, 'a', 3, 3),67 (5, '', 0, 4)68 ])69 """def test_change_order_multiple_changes(self):70 # FAILS... sould I fix it... might work if self extra updates are moved to pre_save... look into that first71 item = Item.objects.filter(list=1, order=0).first()72 item.order = 173 item.save()74 item.order = 275 item.save()76 item.order = 377 item.save()78 post_result = list(79 Item.objects.filter(list=1).order_by("order").80 values_list("id", "updated_by", "order_changed_count", "order"))81 self.assertEqual(post_result,82 [(2, 'Kim-Georg Aase', 1, 0),83 (3, 'Kim-Georg Aase', 1, 1),84 (4, 'Kim-Georg Aase', 1, 2),85 (1, 'Kim-Georg Aase', 3, 3),86 (5, '', 0, 4)...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

1from stories import Stories2from posts import Posts3from reels import Reels4from followers import Followers5from following import Following6import urllib.request7cookies = []8if __name__ == '__main__':9 # Get list user ids from available stories.10 client = Stories(cookies=cookies, debug=True)11 user_ids = client.get_available_stories_user_ids()12 print(user_ids)13 # Get stories from user ids14 client = Stories(cookies=cookies, debug=True)15 stories = client.get_stories_using_user_ids(user_ids=user_ids)16 print(stories)17 # Get Followers from user id18 client = Followers(cookies=cookies, debug=True)19 followers_profiles = client.get_all_followers_profiles_using_user_id(user_id=124)20 print(followers_profiles)21 # Get Followings from user id22 client = Following(cookies=cookies, debug=True)23 following_profiles = client.get_all_following_profiles_using_user_id(user_id=124)24 print(following_profiles)25 img = urllib.request.urlopen(26 'https://instagram.fbho4-1.fna.fbcdn.net/v/t51.2885-19/s320x320/29093337_228763574365850_5571283674877394944_n.jpg?_nc_ht=instagram.fbho4-1.fna.fbcdn.net&_nc_ohc=8-cgeWsuzGMAX8NhY3k&edm=ABfd0MgBAAAA&ccb=7-4&oh=b2ce5cf8af369e33e51942df0f7bd590&oe=60FB15D5&_nc_sid=7bff83')27 photo = img.read()28 # Post a photo29 client = Posts(cookies=cookies, debug=True)30 post_result = client.post_a_picture(data=photo, caption="testing. Please Ignore")31 print(post_result)32 # Post a story33 client = Posts(cookies=cookies, debug=True)34 story_result = client.post_a_story(data=photo, caption="testing. Please Ignore")35 print(story_result)36 # Get a User Reels37 client = Reels(cookies=cookies, debug=True)38 post_result = client.get_reels_using_user_id(user_id=1301203788)39 print(post_result)40 if post_result['max_id']:41 post_result = client.get_reels_using_user_id(user_id=1301203788, max_id=post_result['max_id'])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful