diff --git a/Dockerfile b/Dockerfile index 8f71484..db15677 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,4 @@ RUN pip3 install --upgrade pip RUN pip3 install -r requirements.txt COPY src src COPY server.py server.py -CMD [ "python3", "server.py", "--host=0.0.0.0"] \ No newline at end of file +CMD [ "python3","-u", "server.py"] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8ee4985..4766c47 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ dataclasses~=0.6 SpeechRecognition==3.8.1 pymongo==4.1.1 wget==3.2.0 -#pocketsphinx==0.1.15 +pocketsphinx==0.1.15 oci~=2.54.1 XlsxWriter~=3.0.3 boto3~=1.21.13 @@ -15,4 +15,7 @@ openpyxl==3.0.9 google-cloud-firestore==2.4.0 PySimpleGUI==4.60.1 requests~=2.27.1 -Mako~=1.2.0 \ No newline at end of file +Mako~=1.2.0 +Flask~=2.2.2 +flask_httpauth~=4.7.0 +APScheduler~=3.9.1 \ No newline at end of file diff --git a/server.py b/server.py index e9b13b3..235c55f 100644 --- a/server.py +++ b/server.py @@ -5,15 +5,25 @@ from flask import Flask from flask import jsonify from flask import request from flask_cors import CORS, cross_origin +from flask_httpauth import HTTPTokenAuth from src.workers.SpeechToText import SpeechToText app = Flask(__name__) cors = CORS(app) app.config['CORS_HEADERS'] = 'Content-Type' +auth = HTTPTokenAuth(scheme='Bearer') + +secret_token = "97e36f7e-340e-4c02-b329-9415faee38c3" + + +@auth.verify_token +def verify_token(token): + return token == secret_token @app.route('/', methods=['POST']) +@auth.login_required @cross_origin() def post(): file_name = str(uuid.uuid4()) + ".wav" @@ -21,13 +31,13 @@ def post(): vid.write(request.data) speech_to_text = SpeechToText() result = speech_to_text.to_text(file_name) - print(result) + app.logger.info(result) try: os.remove(file_name) except OSError: - print(OSError) + app.logger.info(OSError) return jsonify(result) if __name__ == '__main__': - app.run(host='0.0.0.0', port=8000, debug=True) + app.run(host='0.0.0.0', port=8000, debug=False) diff --git a/src/db/mongo_manager.py b/src/db/mongo_manager.py index 64be987..1913a16 100644 --- a/src/db/mongo_manager.py +++ b/src/db/mongo_manager.py @@ -233,8 +233,10 @@ class MongoDbManager: def save_links_to_validate(self, link: str): collection_to_use = self.db[LINKS_TO_VALIDATE] + updated_at = time.strftime("%H:%M:%S", time.localtime()) collection_to_use.replace_one(filter={'_id': link, }, replacement={ - u'url': link + u'url': link, + "updated_at": updated_at }, upsert=True) diff --git a/src/mail/get_invoices.py b/src/mail/get_invoices.py index 682e2ca..ae2f4fe 100644 --- a/src/mail/get_invoices.py +++ b/src/mail/get_invoices.py @@ -70,23 +70,6 @@ class InvoiceGetter(): mails_messages.extend(mail_list) return mail_list - # def downloadAllAttachmentsInInbox(self, imap): - # typ, items = imap.search(None, '(SUBJECT "{}" SINCE "{}")'.format(INVOICE_SUBJECT_fr, - # datetime.datetime.today().strftime( - # date_format))) - # items = items[0].split() - # self.downloaAttachmentsInEmail(imap, "./") - # - # def downloaAttachmentsInEmail(self, imap, outputdir): - # resp, data = imap.fetch(HERMES_INVOICE_EMAIL, "(BODY.PEEK[])") - # email_body = data[0][1] - # mail = email.message_from_string(email_body) - # if mail.get_content_maintype() != 'multipart': - # return - # for part in mail.walk(): - # if part.get_content_maintype() != 'multipart' and part.get('Content-Disposition') is not None: - # open(outputdir + '/' + part.get_filename(), 'wb').write(part.get_payload(decode=True)) - def _get_messages_from_folder(self, imap, subject, folder="INBOX") -> list: imap.select(folder) mail_messages = [] @@ -141,36 +124,7 @@ class InvoiceGetter(): return mail_messages -def clean(text): - # clean text for creating a folder - return "".join(c if c.isalnum() else "_" for c in text) - - -def need_to_valid_url(url: str, successful_items) -> bool: - if len(successful_items) == 0: - return False - print("url is :" + url) - parts = url.split('/') - id = parts[5] - if len(id) == 6: - for item in successful_items: - # if item.url_validated is not None: - # print("id:{}, status:{} ".format(id, str(item.url_validated))) - if item.id == id: - if item.url_validated is not None: - return not item.url_validated - else: - # if url_validated is None - return True - # return True by default - return False - else: - print("id not valid:{}".format(id)) - return False - - def get_invoices(): - # check time before start checking emails # get email address mail_list = MONGO_STORE_MANAGER.get_destination_emails() mail_list_to_check = [] diff --git a/src/mail/mail_reader.py b/src/mail/mail_reader.py index 915d03f..510b53c 100644 --- a/src/mail/mail_reader.py +++ b/src/mail/mail_reader.py @@ -131,11 +131,6 @@ class MailReader(): return mail_messages -def clean(text): - # clean text for creating a folder - return "".join(c if c.isalnum() else "_" for c in text) - - def need_to_valid_url(url: str, successful_items) -> bool: if len(successful_items) == 0: return False @@ -167,7 +162,7 @@ def need_to_check_email(mail: str, successful_items) -> bool: for item in successful_items: if mail in item.email: if item.url_validated is not None: - print("url_validated for {} is {}".format(item.url_validated, mail)) + print("url_validated for {} is {}".format(mail, item.url_validated)) return not item.url_validated else: # if url-validated is none, need to check email @@ -205,10 +200,10 @@ def read_mails(): if match: url = match.group(0) if need_to_valid_url(url, successful_items): - # MONGO_STORE_MANAGER.save_links_to_validate(url) - url_validator = LinkValidator(url) + MONGO_STORE_MANAGER.save_links_to_validate(url) + # url_validator = LinkValidator(url) print("need to validate url: " + url) - executor.submit(url_validator.start_page, params.get_proxy(ProxyType.OXYLABS), True) + # executor.submit(url_validator.start_page, params.get_proxy(ProxyType.OXYLABS), False) else: print("do not need to click url --> {}".format(mail.mail_address)) diff --git a/src/utils/send_email_mailjet.py b/src/utils/send_email_mailjet.py index 7aaa5e0..a30170c 100644 --- a/src/utils/send_email_mailjet.py +++ b/src/utils/send_email_mailjet.py @@ -10,13 +10,22 @@ api_secret = "edac41f0e1726ba49808dfb12204ecd6" mailjet = Client(auth=(api_key, api_secret), version='v3.1') from_email = "no-reply@lpaconsulting.fr" # store = "Hermès Paris Faubourg" -store = "Hermès Paris Sèvres" -# store = "Hermès Paris George V" -# dest_email = "0429xiaohan@gmail.com" #小萝卜 -# dest_email = "1340219934@qq.com" #小于 +store = "Hermès Paris George V" +# store = "Hermès Paris Sèvres" +# dest_email = "928490803@qq.com" +# dest_email = "1757344572@qq.com" +# dest_email = "392417782@qq.com" # dest_email = "linghuili@hotmail.com" -dest_email = "landdu@outlook.com" -contact_name = "LI Jiaxi" +# dest_email = "fanfan19810617@icloud.com" +# dest_email = "fanchunying323@163.com" +# dest_email = "lytlaure@gmail.com" +dest_email = "arianezhangsn@yahoo.com" +# dest_email = "sunrose75015@gmail.com" +# dest_email = "1340219934@qq.com" +# dest_email = "lytlaure@gmail.com" +# dest_email = "m13805869912@163.com" +# dest_email = "tangliang0411@gmail.com" +contact_name = "LU yaping" f = open(config.ROOT_DIR + "/templates/confirmed_rdv.html", "r") email_body = f.read() diff --git a/src/workers/commandor_page.py b/src/workers/commandor_page.py index fa4b490..99f2c12 100644 --- a/src/workers/commandor_page.py +++ b/src/workers/commandor_page.py @@ -97,7 +97,7 @@ class CommandorPage: self.otp_value = None # device = None device_key = random.choice(params.DEVICES) - device_key = random.sample(list(self.tls.playwright.devices), 1)[0] + # device_key = random.sample(list(self.tls.playwright.devices), 1)[0] device = self.tls.playwright.devices[device_key] # while device is None: # device_key = random.sample(list(self.tls.playwright.devices), 1)[0] @@ -417,7 +417,6 @@ class CommandorPage: def handle_captcha_error(self): MONGO_STORE_MANAGER.insert_captcha_error_contact(self.contact) - params.oracle_log_sender.send_captcha_error(self.contact) def check_is_blocked(self) -> bool: iframe = self.page.query_selector('iframe').content_frame()