-
Notifications
You must be signed in to change notification settings - Fork 1
/
ctripref.py
119 lines (101 loc) · 3.96 KB
/
ctripref.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
# coding=utf-8
import pprint
# import csv
import click
# import requests
# import datetime as datetime
# from datetime import date
# from xml.etree import ElementTree as ET
import os
# from random import sample
# import random
# import json
# import logging
import subprocess
import glob
import time
import sys
import datetime
import re
def is_bad_date(filename_regex, newest):
today_date = datetime.datetime.now().strftime('%y%m%d')
try:
newest_date = re.search(filename_regex, newest).group(1)
except AttributeError:
newest_date = ''
if newest_date != today_date:
print('Error: newest date != today date.. mannual intervention needed..')
return True
print('newest date: ' + newest_date)
return False
def is_bad_date_re(filename_regex, newest):
today_date = datetime.datetime.now().date()
try:
newest_date = re.search(filename_regex, newest).group(1)
except AttributeError:
newest_date = ''
try:
newest_date = datetime.datetime.strptime(newest_date , '%y%m%d').date()
except ValueError:
print('Error: Unable to convert date')
return True
if newest_date < today_date:
print('Error: newest date < today date.. mannual intervention needed..')
return True
print('newest date: ' + str(newest_date))
return False
# hua shi shui jiao
def hua_style_sleep():
for i in range(3):
print('sleeping..' + str(i))
time.sleep(1)
@click.command()
@click.option('--days', default=0, type=int)
@click.option('--duration', default=3, type=int)
# @click.option('--days', default=1, type=int)
def ctripref(days, duration):
subprocess.call(['python', 'booking_id_ctrip.py', '--days', str(days), '--duration', str(duration), '--d_type', 'departure'])
newest = max(glob.iglob('output_Search_booking_id_*.csv'), key=os.path.getctime)
# if is_bad_date('output_Search_booking_id_(\d+)', newest):
if is_bad_date_re('output_Search_booking_id_(\d+)', newest):
print('Error: bad date.. ')
return
subprocess.call(['python', 'ctrip_store_booking.py', '--filename', newest, '--days', '-30', '--output', 'output_ctrip_search_booking_store.csv'])
subprocess.call(['python', 'search_item_hr.py', '--filename', newest])
hua_style_sleep()
newest = max(glob.iglob('output_Search_item_hr_*.csv'), key=os.path.getctime)
# if is_bad_date('output_Search_item_hr_(\d+)', newest):
if is_bad_date_re('output_Search_item_hr_(\d+)', newest):
print('Error: bad date.. ')
return
# subprocess.call(['python', 'hc.py', '--filename', newest])
subprocess.call(['python', 'hc_pool.py', '--filename', newest])
hua_style_sleep()
# newest = max(glob.iglob('output_Search_item_hr_*.csv'), key=os.path.getctime)
# subprocess.call(['python', 'sendmail.py', '--filename', 'output_hotel_ref_*.csv', '--title', 'Ctrip_hotel_ref'])
newest = max(glob.iglob('output_hotel_ref_*.csv'), key=os.path.getctime)
# if is_bad_date('output_hotel_ref_(\d+)', newest):
if is_bad_date_re('output_hotel_ref_(\d+)', newest):
print('Error: bad date.. ')
return
# while True:
# sys.stdout.write("Would you like to proceed to call Ctrip's update hotel res no API? " + newest + " [Y/N]")
# choice = input().lower()
# if choice == 'y' or choice == 'yes':
# break
# if choice == 'n' or choice == 'no':
# return
subprocess.call(['python', 'ctrip_update_res_no.py', '--filename', newest])
# keep track of bookings that has been pushed
newest = max(glob.iglob('output_ctrip_update_res_no_*.csv'), key=os.path.getctime)
# if is_bad_date('output_ctrip_update_res_no_(\d+)', newest):
if is_bad_date_re('output_ctrip_update_res_no_(\d+)', newest):
print('Error: bad date.. ')
return
subprocess.call(['python', 'ctrip_store_booking.py', '--filename', newest, '--days', '-30', '--output', 'output_ctrip_booking_store.csv'])
subprocess.call(['python', 'sendmail_win_cs.py',
'--filename', 'output_hotel_ref_',
'--email', '[email protected]'])
if __name__ == '__main__':
ctripref()