def new_enterprise_main(): """ 获取新增企业数据 :return: """ r = connect_redis(0, 110) for url, city, province in creat_url(): handle_page(url, city, province, r) print(get_yesterday(), 'end')
def get_more_data_main(): """ 这里可以开并发加代理,没用好的代理源暂时放弃 :return: """ r = connect_redis(0, 110) for key in r.keys(): data = eval(r.get(key)) threading.Thread(target=get_more_data, args=(key, r, data)).start() sleep(5)
def new_enterprise_main(): """ 获取新增企业数据 :return: """ global device_id, tim, sign, header device_id, tim, sign, header = more_get_token() r = connect_redis(0, 110) for url, city, province in creat_url(): handle_page(url, city, province, r) sleep(1.5)
from auth.models import * from admin.models import * from canteen.models import * from common.utils import connect_db from common.utils import connect_redis connect_db() connect_redis()
def sql_many_ex(sql, datas): conn = pymysql.Connect(host='127.0.0.1', port=3306, user='******', password='******', database='qidatas') cursor = conn.cursor() cursor.executemany(sql, datas) conn.commit() # 插入省份 "INSERT INTO Province(code,pname) values (%(province)s,%(name)s)" # 插入城市 "INSERT INTO city(id,city_name,p_code,p_name) values (%(Value)s,%(Desc)s,%(provinceCode)s,%(provinceName)s)" if __name__ == '__main__': sql = "REPLACE INTO qidata(KeyNo,Name,CreditCode,StartDate,Address,RegistCapi,ShortStatus,City,Province,EconKind,OperName,Scope,SubIndustry,TermStart,TeamEnd,OrgNo,BelongOrg,phone,ImageUrl,EndDate,IsOnStock,county,Partnersid,Email) values (%(KeyNo)s,%(Name)s,%(CreditCode)s,%(StartDate)s,%(Address)s,%(RegistCapi)s,%(ShortStatus)s,%(City)s,%(Province)s,%(EconKind)s,%(OperName)s,%(Scope)s,%(SubIndustry)s,%(TermStart)s,%(TeamEnd)s,%(OrgNo)s,%(BelongOrg)s,%(phone)s,%(ImageUrl)s,%(EndDate)s,%(IsOnStock)s,%(county)s,%(Partnersid)s,%(Email)s)" datas = [] i = 0 r1 = connect_redis() for key in r1.keys(): i += 1 data = r1.get(key) data = eval(data) key = str(key, encoding='utf8') # province, city, county = cpca_data(data.get('Address')) #cpca_data jieba分词方法 # data['county'] = county data['KeyNo'] = data.get('KeyNo') if data.get('KeyNo') else key[key.find(':') + 1:] data['EconKind'] = data.get('EconKind') data['Scope'] = data.get('Scope') data['SubIndustry'] = data.get('SubIndustry') data['TermStart'] = data.get('TermStart') data['TeamEnd'] = data.get('TeamEnd') data['OrgNo'] = data.get('OrgNo') data['BelongOrg'] = data.get('BelongOrg')
# -*- coding: utf-8 -*- from biz import models from common.utils import connect_redis redis_conn = connect_redis() def get_foodtype_list(): foodtype_list = models.FoodType.objects.all() return foodtype_list def create_foodtype(name=''): foodtype = models.FoodType(name=name) foodtype.save() return foodtype def get_foodtype(foodtype_id): foodtype = models.FoodType.objects.get(id=foodtype_id) return foodtype def update_foodtype(foodtype_id, **kwargs): foodtype = get_foodtype(foodtype_id) for key, value in kwargs.iteritems(): foodtype[key] = value foodtype.save() return foodtype
# -*- coding: utf-8 -*- from biz import models from common.utils import connect_redis redis_conn = connect_redis() def get_foodtype_list(): foodtype_list = models.FoodType.objects.all() return foodtype_list def create_foodtype(name=''): foodtype = models.FoodType(name=name) foodtype.save() return foodtype def get_foodtype(foodtype_id): foodtype = models.FoodType.objects.get(id=foodtype_id) return foodtype def update_foodtype(foodtype_id, **kwargs): foodtype = get_foodtype(foodtype_id) for key, value in kwargs.iteritems(): foodtype[key] = value foodtype.save() return foodtype