You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
microscript-base/main.py

61 lines
2.3 KiB

from flask import Flask
from mock_response import MOCK_RESPONSE
app = Flask(__name__)
@app.route("/")
def index():
return MOCK_RESPONSE
if __name__ == "__main__":
app.run(port=8080)
def transactions_pull(mongodb):
if not const.LHV_IMPORT:
return ""
last_timestamps = {}
for self_account in SELF_ACCOUNTS:
last_timestamps[self_account] = date(2015, 1, 1)
for row in mongodb.cashflow.find({"type": "transaction", "self_account": self_account}).sort([("_id",-1)]).limit(1):
last_timestamps[self_account] = datetime.strptime(row["timestamp"], "%Y-%m-%d")
today = date.today()
for self_account in SELF_ACCOUNTS:
created = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.000")
start = last_timestamps[self_account].strftime("%Y-%m-%d")
finish = today.strftime("%Y-%m-%d")
# zomg what
while True:
response = requests.get("https://connect.lhv.eu/messages/next", cert=KEYPAIR)
msg_id = response.headers.get("Message-Response-Id")
if not msg_id:
break
print("Discarding:", msg_id)
response = requests.delete("https://connect.lhv.eu/messages/%s" % msg_id, cert=KEYPAIR)
response = requests.post("https://connect.lhv.eu/account-statement", data=BUF % locals(), cert=KEYPAIR)
sleep(2)
response = requests.get("https://connect.lhv.eu/messages/next", cert=KEYPAIR)
buf = response.content
if not buf:
raise ValueError("Failed to retrieve next %s" % response.status_code)
for values in import_statements(buf):
mongodb.cashflow.update_one({
"type": "transaction",
"reference": values[0]
}, {
"$set": {
"timestamp": values[1],
"self_account": values[2],
"peer_account": values[3],
"peer_name": values[4],
"peer_name_normalized": norm(normalize_legal_entity(values[4])),
"credit_debit": values[5],
"amount": values[6],
"comment": values[7]
},
}, upsert=True)
auto_associate(mongodb)
requests.get("https://hc-ping.com/375391a5-ff13-47e3-8892-876d1d995058")
return "ok"