def quchong_list(): key = 'list_skin*' list_wrap = cloudfunc.run('keys', key=key) for i in list_wrap: result = cloudfunc.run('get_list_item', key=i, begin=0, end=-1) news_li = [] for item in result: if item not in news_li: news_li.append(item) upload_list(i, news_li)
def update_team_act(title,image): with open('/Users/mac/spader/resource/team_text.txt', 'r+') as fr: content = fr.read() set_content = cloudfunc.run('setField', key='settings', field='teams_gift_content', value=content) set_image = cloudfunc.run('setField', key='settings', field='teams_gift_images', value=image) set_title = cloudfunc.run('setField', key='settings', field='teams_gift_title',value=title) print(set_content) print(set_image) print(set_title) # update_team_act('雅诗兰黛小棕瓶拼手气红包,手气最佳免费赠送','http://lc-XBtceMXX.cn-n1.lcfile.com/1643f7223eca3ab7573f/WechatIMG2446.jpeg')
def up_matsukiyo(url): f = open(url, 'r') csv_file = csv.reader(f) # del_list_key = cloudfunc.run('del_key', key=list_key) # del_sub_list_key = cloudfunc.run('del_key', key=sub_list_key) for item in csv_file: goods = {} # list_key = list_title_1 + item[0] # sub_list_key = list_title_2 + item[1] key = 'item_' + item[2] goods['key'] = key goods['pid'] = item[2] goods['brand'] = item[4] goods['name'] = item[5] goods['size'] = item[5] goods['content'] = item[8] goods['price'] = item[6] goods['fee'] = 6 goods['tax'] = 0 goods['image'] = item[9] goods['images'] = json.dumps([]) source_object = {} source_object['id'] = 1001 source_object['shop'] = '松本清' source_object['country'] = '日本' goods['source'] = json.dumps(source_object) for field, value in goods.items(): print(field, value) try: set_item = cloudfunc.run('setField', key=key, field=field, value=value) except: pass try: push_sub_list = cloudfunc.run('lpush', key=list_key, value=key) except: pass try: push_sub_sub_list = cloudfunc.run('lpush', key=sub_list_key, value=key) except: pass
def test_fix_search(self): user = leancloud.User().become( "eyJhbGciOiJIUzI1NiIsImlhdCI6MTUyOTkxNTQyMywiZXhwIjoxNTMzNTE1NDIzfQ.IjQi.ttcDTMSAszLP7F3TJieiCCzYV6j0o0D8pMFgnMkGCwI" ) ret = cloudfunc.run('search', keyword="测", belongGroupId="8") print(ret) assert (type(ret) == dict)
def send_subscribe_message(objectid, message): data = message data['touser'] = objectid ge = cloudfunc.run('send_subscribe_message', data=json.dumps(data), programid=programid) print(ge)
def test_modify_user(self): user = leancloud.User().become(session_token) print(user.dump()) ret = cloudfunc.run('modifyUserInfo', password="******", firstName="晓华", lastName="郑", email="[email protected]", defaultGroupId=2, avatar="https://www.gravatar.com/avatar/0efa74fe76da7681da2939b3214e5cdf?s=328&d=identicon&r=PG", ) print(ret) assert (type(ret) == dict)
def get_goods_info(data,file): obj = {} name = '' func = 'goods' # 类型 出售 还是 求购 if re.search('收', data) is not None: name = '求购' obj['type'] = 2 elif re.search('求', data) is not None: name = '求购' obj['type'] = 2 elif re.search('出', data) is not None: name = '出售' obj['type'] = 1 else: return None # 商品名 obj['brand'] = None for item in brand: result = re.search(item['name'], data) if result is not None: obj['brand'] = item['value'] if obj['brand']: pass else: return None # 价格 if re.search(r'(\d)(\d)(\d)(\d)', data) is not None: obj['price'] = re.search(r'(\d)(\d)(\d)(\d)', data).group() elif re.search(r'(\d)(\d)(\d)', data) is not None: obj['price'] = re.search(r'(\d)(\d)(\d)', data).group() elif re.search(r'(\d)(\d)', data) is not None: obj['price'] = re.search(r'(\d)(\d)', data).group() else: obj['price'] = None obj['msg'] = data obj['time'] = int(time.time() * 1000) obj['uid'] = '10000000' try: file.writerow([ obj['type'], obj['brand'], obj['price'], obj['time'], obj['uid'], obj['msg'] ]) except: print('没有记录在csv') print(obj) result = cloudfunc.run( 'card', func=func, type=obj['type'], brand=obj['brand'], price=obj['price'], time=obj['time'], uid=obj['uid'], msg=obj['msg']) print(result) return obj
def up_haidaisi(url): f = open(url, 'r') csv_file = csv.reader(f) # del_list_key = cloudfunc.run('del_key', key=list_key) # del_sub_list_key = cloudfunc.run('del_key', key=sub_list_key) for item in csv_file: goods = {} list_key = list_title_1 + item[0] sub_list_key = list_title_2 + item[1] key = 'item_' + item[0] goods['key'] = key goods['pid'] = item[0] goods['brand'] = item[1] goods['name'] = item[5] goods['size'] = item[5] goods['content'] = item[12] goods['price'] = int(item[10]) + 15 goods['fee'] = 6 goods['tax'] = 0 goods['image'] = item[13] goods['links'] = item[15] goods['images'] = json.dumps(item[14]) source_object = {} source_object['id'] = item[4] source_object['shop'] = item[3] source_object['country'] = '日本' goods['source'] = json.dumps(source_object) print(item[0]) for field, value in goods.items(): try: set_item = cloudfunc.run('setField', key=key, field=field, value=value) except: pass try: push_sub_list = cloudfunc.run('lpush', key=list_key, value=key) except: pass
def del_list_item_key(lst): r1 = cloudfunc.run('query_list', key=lst, begin=0, end=-1) print(r1) for item in r1: print(item) r2 = cloudfunc.run('del_one_key', key=item) r3 = cloudfunc.run('del_one_key', key=lst) # del_list_item_key('list_wish_lottery') # up_massage('/Users/mac/spader/download/0330/12345.csv') # up_sephora('/Users/mac/spader/download/sephora.csv') # list_haidaisi(url) # push_item_to_list('/Users/mac/spader/resource/beauty.csv') # up_haidaisi(url) # r1 = cloudfunc.run('del_key', key='list_s*') # r1 = cloudfunc.run('del_key', key='list_sephora_sub_top100') # r1 = cloudfunc.run('del_key', key='list_dr*') # msg_to_json()
def up_sephora(url): f = open(url, 'r') csv_file = csv.reader(f) for item in csv_file: key = 'item_' + item[4].strip() sku = json.dumps(eval(item[10])) content = item[11] # up_sku = cloudfunc.run('setField', key=key, field='sku', value=sku) # up_content = cloudfunc.run('setField', key=key, field='content', value=content) push_sub_sub_list = cloudfunc.run('rpush', key='list_sephora_aaa', value=key) print(push_sub_sub_list)
def update_lottery_result(): # 1.设置当期中奖的数据 lottery_result = cloudfunc.run('setField', key='lottery_result', field=str(times),value=codes) # 2.settings 里设置 period period = cloudfunc.run('setField', key='settings', field='period',value=times+1) # 3.lottery_app_settings 的 first_reward first_reward = cloudfunc.run('setField', key='lottery_app_settings', field='first_reward',value=lotterys_first_get) # 4.lottery_app_settings 的 second_reward first_reward = cloudfunc.run('setField', key='lottery_app_settings', field='second_reward',value=lotterys_second_get) # 5.lottery_app_settings 的 lotterys first_reward = cloudfunc.run('setField', key='lottery_app_settings', field='lottery_times',value=lotterys) # 6.lottery_app_settings 的 period first_reward = cloudfunc.run('setField', key='lottery_app_settings', field='period',value=times+1) # 7.lottery_app_settings 的 pre_code first_reward = cloudfunc.run('setField', key='lottery_app_settings', field='pre_code',value=codes) # 8.lottery_app_settings 的 pre_period first_reward = cloudfunc.run('setField', key='lottery_app_settings', field='pre_period',value=times)
def list_haidaisi(url): f = open(url, 'r') csv_file = csv.reader(f) for item in csv_file: if item[7]: try: push_sub_list = cloudfunc.run('lpush', key=item[7], value='item_' + item[0]) print(push_sub_list) except: pass finally: pass else: pass
def push_list(): key = 'list_skincare_0001' lst = [ '92005242', '92005452', '92004048', '92008254', '92004489', '92000001', '92000146', '92000619', '92000118', '92000120', '92000943', '92005813', '92001777', '92001780', '92006574', '92002356', '92002357', '92002359', '92003729', '92001757', '92001758', '92001759', '92001760', '92001761', '92001762', '92001763', '92001764', '92001765', '92004819', '92004820', '92008288', '92002026', '92002083', '92002341', '92004729', '92001827', '92001827', '92001827', '92003144', '92003145', '92003146', '92003147', '92006574', '92006574', '92001058', '92001059', '92001060', '92004123', '92006575', '92006576', '92006577', '92000005' ] for item in lst: i = 'item_' + item result = cloudfunc.run('lpush', key=key, value=i) print(result)
def up_massage(url): f = open(url, 'r') csv_file = csv.reader(f) # del_list_key = cloudfunc.run('del_key', key=list_key) # del_sub_list_key = cloudfunc.run('del_key', key=sub_list_key) for item in csv_file: goods = {} key = 'item_' + item[0] goods['key'] = key goods['id'] = item[0] goods['brand'] = item[3] goods['name'] = item[4] goods['size'] = item[4] goods['content'] = item[6] goods['price'] = item[5] goods['fee'] = 6 goods['tax'] = 0 goods['image'] = item[8] images = [] if item[9]: images.append(item[9]) goods['images'] = json.dumps(images) source_object = {} source_object['id'] = 1002 source_object['shop'] = '丝芙兰' source_object['country'] = '美国' goods['source'] = json.dumps(source_object) # print(goods) # print(item[2],key) # for field, value in goods.items(): # print(field, value) # try: # set_item = cloudfunc.run( # 'setField', key=key, field=field, value=value) # except: # pass if item[2]: try: push_sub_list = cloudfunc.run('rpush', key=item[2], value=key) print(push_sub_list) except: pass
def push_item_to_list(url): f = open(url, 'r') csv_file = csv.reader(f) for i in csv_file: # # 设置brand # try: # if i[1]: # print(i[1], 'item_' + i[0]) # result = cloudfunc.run('rpush', key=i[1], value='item_' + i[0]) # print(result) # except: # pass # 设置版本 try: print('item_' + i[0], i[8]) result = cloudfunc.run('setField', key='item_' + i[0], field='edition', value='日本本土专柜版') print(result) except: pass
def download_goods(url, list_key): f = open(url, 'a+') writer = csv.writer(f) #创建写的对象 lists = [] result = cloudfunc.run('get_list_details_new', key=list_key, begin=0, end=-1) for item in result: name = item.get('name') _id = item.get('id') price = item.get('price') image = item.get('image') key = item.get('key') ll_times = item.get('ll_times') limit_lottery_ended = item.get('limit_lottery_ended') gl_times = item.get('gl_times') group_lottery_ended = item.get('group_lottery_ended') lists.append([ _id, name, image, '', '', price, ll_times, limit_lottery_ended, gl_times, group_lottery_ended ]) writer.writerows(lists)
import csv import requests import leancloud from leancloud import cloudfunc from io import StringIO leancloud.init("0EaEC5sQIVi9vLFPkeWwLoPN-gzGzoHsz", master_key="NCjeEh0PTMAiY43KWWk6ks1T") # 查询所有用户 ge = cloudfunc.run('keys', key='user_*') for item in ge: user = cloudfunc.run('getHash', key=item) print(user.get('uid', ''), user.get('nickName', ''), user.get('f_balance', ''), user.get('image', ''), user.get('objectid', ''))
#下载某一个list中的所有商品 import csv import leancloud from datetime import datetime import json from leancloud import cloudfunc leancloud.init("XBtceMXXkxxRQez6lQBCJ8UK-gzGzoHsz", master_key="KlbmMqYVvcOC7adJvwoRO9Ww") good_csv = [] goods_list = cloudfunc.run('query_listing_and_goods', list_id='10000014') for goods in goods_list['goods']: good = [] good.append(goods.get('id', '')) good.append(goods.get('name', '')) good.append(goods.get('tags', '')) good.append(goods.get('sub_name', '')) good.append(goods.get('prior', '')) good.append(goods.get('price', '')) good.append(goods.get('content', '')) good.append(goods.get('images', '')) good.append(goods.get('share_discount', '')) good.append(goods.get('fee', '')) good.append(goods.get('trans_fee', '')) good.append(goods.get('commission', '')) good.append(goods.get('reason', '')) good.append(goods.get('remark', '')) good.append(goods.get('details', '')) good.append(goods.get('infors', ''))
def list_items(wrap, key): result = cloudfunc.run('lpush', key=wrap, value=key) print(result)
def test_client(): leancloud.init(os.environ['APP_ID'], os.environ['APP_KEY']) assert cloudfunc.run('add', a=1, b=2) == 3
def test_read_news(self): user = leancloud.User().become(session_token) ret = cloudfunc.run('readNews', isMark=1, newsId=1) print(ret) assert (type(ret) == dict)
def object_to_json_update_to_field(key, field, value): dt = json.dumps(value) print(key, field) print(dt) load = cloudfunc.run('setField', key=key, field=field, value=dt) print(load)
datas = query.datas[skip:limit] except IndexError: return redirect("/mobile") content = template.render(datas=datas) return content application = Engine(default_app()) @application.define def update(**kwargs): fetcher = storage.Fetch() query = storage.Query() query.cleanData() fetcher.fetch_all() storage.Fetch.Live.save_all(fetcher.lives[:120]) @application.define def change_version(version, **kwargs): global VERSION VERSION = version if __name__ == '__main__': from leancloud import cloudfunc cloudfunc.run("change_version", version='v2.1') # cloudfunc.run("update")
def update_lottery_result(): result = cloudfunc.run('get_list_item', key='list_handsel', begin=0, end=-1) for item in result: good = cloudfunc.run('getHash', key=item) key = "hs_{}_{}".format(uid, good['id']) total = '{}00'.format(good['price']) paid = int(total) - 47 goodid = good['id'] print(key,total,paid,goodid,uid,times) cloudfunc.run('setField', key=key, field='expired', value=expired) cloudfunc.run('setField', key=key, field='total', value=total) cloudfunc.run('setField', key=key, field='key', value=key) cloudfunc.run('setField', key=key, field='paid', value=paid) cloudfunc.run('setField', key=key, field='goodid', value=goodid) cloudfunc.run('setField', key=key, field='times', value=times) cloudfunc.run('setField', key=key, field='uid', value=uid)
def rcv_msg(g, s, u, r, c): cloudfunc.run('rcv_msg', g=g, s=s, u=u, r=r, c=c)
def redis_items(key, field, value): result = cloudfunc.run('setField', key=key, field=field, value=value) print(result)
#上传 list import csv import leancloud from datetime import datetime import json from leancloud import cloudfunc leancloud.init("XBtceMXXkxxRQez6lQBCJ8UK-gzGzoHsz", master_key="KlbmMqYVvcOC7adJvwoRO9Ww") f = open('/Users/mac/spader/upload/list_0108.csv', 'r') csv_file = csv.reader(f) for item in csv_file: # print(item) goods = {} goods['list_id'] = item[0] goods['shop_desc'] = item[1] goods['shop_name'] = item[2] goods['shop_images'] = item[3] result = cloudfunc.run('up_load_list_to_redis_from_execl', datas=goods) print('完成')
def upload_list(key, l): del_list = cloudfunc.run('del_key', key=key) for item in l: load = cloudfunc.run('rpush', key=key, value=item) print(key, item)
import csv import leancloud from datetime import datetime import json from leancloud import cloudfunc leancloud.init("XBtceMXXkxxRQez6lQBCJ8UK-gzGzoHsz", master_key="KlbmMqYVvcOC7adJvwoRO9Ww") good_csv = [] goods_list = cloudfunc.run('getListItemHash', key='gid_*') for goods in goods_list: good = [] good.append(goods.get('id', '')) good.append(goods.get('name', '')) good.append(goods.get('tags', '')) good.append(goods.get('sub_name', '')) good.append(goods.get('prior', '')) good.append(goods.get('price', '')) good.append(goods.get('content', '')) good.append(goods.get('images', '')) good.append(goods.get('share_discount', '')) good.append(goods.get('fee', '')) good.append(goods.get('trans_fee', '')) good.append(goods.get('commission', '')) good.append(goods.get('reason', '')) good.append(goods.get('remark', '')) good.append(goods.get('details', '')) good.append(goods.get('infors', '')) good.append(goods.get('list_id', '')) good_csv.append(good)
# newTravelNote.set("startDate",datetime.datetime.strptime("2018-05-06 18:00:00", "%Y-%m-%d %H:%M:%S")) # newTravelNote.set("endDate",datetime.datetime.strptime("2018-05-06 20:00:00","%Y-%m-%d %H:%M:%S")) # newTravelNote.set("spend",10) # newTravelNote.set("content","啊~嗯!") # newTravelNote.save() # print travel.id # user.set("email","*****@*****.**") # user.save() print cloudfunc.run( 'publishTravelNote', guideID='5aeef1d1ac502e607645d6b2', target="zhengzhou", peopleNum=10, theme="SM", path="暗黑功德箱-》更衣室-》B站", startDate="2018-01-01 00:00:00", endDate="2018-02-01 00:00:00", spend=10, content="Deep Dark Fantacy", title="啊♂", ) # TravelNote = leancloud.Object.extend("TravelNote") # query = TravelNote.query # query.equal_to("area","武汉") # query_list = query.find() # for i in query_list: # content = i.get("content") # if type(content)!=types.NoneType: # picUrls_pre = re.findall('<img.*?>', content) # html的提取img标签的正则表达式 # else:
def test_client(): leancloud.init('pgk9e8orv8l9coak1rjht1avt2f4o9kptb0au0by5vbk9upb', 'hi4jsm62kok2qz2w2qphzryo564rzsrucl2czb0hn6ogwwnd') assert cloudfunc.run('add', a=1, b=2) == 3
def test_client(): leancloud.init(os.environ['appid'], os.environ['appkey']) assert cloudfunc.run('add', a=1, b=2) == 3