parent
86ec8db612
commit
82f13d14ac
3 changed files with 88 additions and 1 deletions
@ -0,0 +1,36 @@ |
||||
import datetime |
||||
import csv |
||||
from io import StringIO |
||||
from django_redis import get_redis_connection |
||||
|
||||
|
||||
# 清除redis锁 |
||||
def clear_lock_func(): |
||||
redis_conn = get_redis_connection() |
||||
redis_key = f'ai_show{datetime.date.today().strftime("%Y%m%d")}' |
||||
if redis_conn.exists(redis_key): |
||||
redis_conn.delete(redis_key) |
||||
|
||||
|
||||
# 将csv转化成字典 |
||||
def scv_to_obj(csv_data): |
||||
f = StringIO(csv_data) |
||||
reader = csv.DictReader(f) |
||||
return list(reader) |
||||
|
||||
|
||||
# 列表转csv |
||||
def list_to_csv(rows, include_header=True): |
||||
""" |
||||
将嵌套列表转换为 CSV 字符串 |
||||
:param rows: 输入数据,格式为 [['col1','col2'], ['val1','val2'], ...] |
||||
:param include_header: 若为 True,则 rows[0] 作为表头;否则全部当作数据行 |
||||
""" |
||||
output = StringIO() |
||||
writer = csv.writer(output, lineterminator='\r\n') |
||||
if include_header and rows: |
||||
writer.writerow(rows[0]) |
||||
writer.writerows(rows[1:]) |
||||
else: |
||||
writer.writerows(rows) |
||||
return output.getvalue() |
||||
@ -0,0 +1,45 @@ |
||||
from django.db.models import Q |
||||
import datetime |
||||
from ai.models import * |
||||
from ai.utils.show_database import GetData |
||||
|
||||
def get_cinema_show_result_func(_zz_code, _show_date): |
||||
cinema = TestCinema.objects.filter(zz_code=_zz_code).first() |
||||
start = datetime.datetime.strftime(datetime.datetime.strptime(_show_date, '%Y-%m-%d') + datetime.timedelta(hours=6), |
||||
'%Y-%m-%d %H:%M:%S') |
||||
end = datetime.datetime.strftime( |
||||
datetime.datetime.strptime(_show_date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59, seconds=59), |
||||
'%Y-%m-%d %H:%M:%S') |
||||
show = '' |
||||
income = '' |
||||
if cinema: |
||||
print(cinema) |
||||
data = GetData(cinema) |
||||
show = data.get_show_data(start, end) |
||||
income = data.get_total_income(start, end) |
||||
print(show, income) |
||||
show_db = AiShow.objects.filter(Q(is_ai_show=False) & Q(zz_code=_zz_code) & Q(show_date=_show_date)).order_by( |
||||
'-id').first() |
||||
if show_db: |
||||
print('show_db', show_db) |
||||
show_db.show = show |
||||
show_db.income = income |
||||
show_db.save() |
||||
else: |
||||
try: |
||||
AiShow.objects.create( |
||||
cinema=cinema.name, |
||||
zz_code=cinema.zz_code, |
||||
show_date=_show_date, |
||||
is_ai_show=False, |
||||
show=show, |
||||
sales=income, |
||||
prompt='', |
||||
result='', |
||||
message='', |
||||
take_times=0, |
||||
take_tokens='0' |
||||
) |
||||
except Exception as e: |
||||
print(e) |
||||
return show, income |
||||
Loading…
Reference in new issue