Select Git revision
enqueue_local_xml.py
-
Eunhak Lee authoredEunhak Lee authored
enqueue_local_xml.py 1.39 KiB
import dotenv
dotenv.load_dotenv(dotenv_path=".env", override=False)
import os
import re
import sys
import time
import redis
import psycopg2
import traceback
import utils
import parse
def _put_docuument(_code, _transaction_id, _user_id, _document):
R.set(f"mypc:code:{_code}:user_id", _user_id)
R.set(f"mypc:code:{_code}:transaction_id", _transaction_id)
R.set(f"mypc:code:{_code}:document", _document)
R.rpush(f"mypc:queue", _code)
if __name__ == "__main__":
global R
R = utils.env_connect_redis()
if not R:
exit(1)
global db_conn
db_conn = utils.env_connect_postgresql()
if not db_conn:
exit(1)
try:
filename = input("Select filename: ")
code = input("Select code: ")
transaction_id = input("Select transaction_id: ")
user_id = int(input("Select user_id: "))
_xml = open(filename, "r", encoding="utf-8").read()
print("\n")
print("Code:", code)
print("Transaction ID:", transaction_id)
print("User ID:", user_id)
print("Document:", "\\n".join([line for line in _xml.split("\n", 5)[:3]]))
_go = input("Continue? (y)") or "y"
if _go.lower() == "y":
print("GO!")
_put_docuument(code, transaction_id, user_id, _xml)
print("Done!")
finally:
print("\n\nEnding program...")
R.close()
db_conn.close()