0
私のデータベースは、このスクリプトの実装では、データベースが失われている、多かれ少なかれ、空のデータがたくさんあることがあります。ありがとう 設定情報の次のリスト: sqlite3の Django1.9.8 のPython 2.7.6マルチプロセッシングdjangoモデルデータベース
def flush_price():
logging.error("Sub-process(es) begin.")
logging.error(int(time.time()))
key = '2500_wine_info.xlsx'
lists = import_excel(key)
lwin11s = []
for item in lists:
lwin11s.append(str(item['LWIN11'])[:11])
contracts = Contract.objects.filter(
is_del=False,
wine__lwin11__in=lwin11s
)
lwins = []
for contract in contracts:
lwins.append(str(contract.wine.lwin))
new_arrs = arr_split(lwins, 50)
now = conversion_reduce_8_time()
for index in range(1, 3641):
date_now = (now - datetime.timedelta(days=index)).strftime('%Y-%m-%d')
pool = multiprocessing.Pool(processes=len(new_arrs))
for new_arr in new_arrs:
pool.apply_async(request_price, (new_arr, date_now,))
pool.close()
pool.join()
break
logging.error(int(time.time()))
logging.error("Sub-process(es) done.")
def request_price(new_arr, date_now):
headers = {
'CLIENT_KEY': CLIENT_KEY,
'CLIENT_SECRET': CLIENT_SECRET,
'ACCEPT': 'application/json',
'CONTENT-TYPE': 'application/json',
}
data = {
'lwin': new_arr,
'priceType': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'],
"currency": "EUR",
"priceDate": date_now,
}
price_obj = download_page(VINEX_PRICE_API, request_type=1, data=json.dumps(data), headers=headers)
if price_obj.status_code == 200:
price_obj = price_obj.json()
if price_obj['httpCode'] == '200':
lwin_details = price_obj['lwinDetail']
for lwin_detail in lwin_details:
# 取得参数
lwin = lwin_detail['lwin']
# 取得对象信息
contract = Contract.objects.filter(is_del=False, wine__lwin=lwin).first()
wine = contract.wine
# 设置历史数据更新
RedWinePriceData.objects.filter(
is_del=False,
contract=contract,
lwin=lwin,
).first()
redwinepricedata = RedWinePriceData()
redwinepricedata.contract = contract
redwinepricedata.lwin = lwin
# 改变数据
redwinepricedata.priceDate = format_time(detail['priceDate'])
redwinepricedata.save()
redwinepricedata.created = add_conversion_8_time(date_now)
redwinepricedata.save()
Change the database information before。 The changed database information
django.dbインポート接続 connection.close() – loopbing