aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/globeop.py (renamed from python/download_daily.py)60
-rw-r--r--python/upload_daily.py45
2 files changed, 53 insertions, 52 deletions
diff --git a/python/download_daily.py b/python/globeop.py
index 255b8c8c..a3bccb51 100644
--- a/python/download_daily.py
+++ b/python/globeop.py
@@ -4,9 +4,9 @@ import datetime
from ftplib import FTP
import gnupg
import config
-import sys
import re
import logging
+import argparse
try:
import pandas as pd
@@ -77,12 +77,58 @@ def download_data(workdate):
passphrase=config.key_password)
os.remove(os.path.join(root, str(workdate), "Reports", filename))
+def upload_data(startdate):
+ for i in range(10):
+ workdate = startdate - datetime.timedelta(days=i)
+ workdatestr = str(workdate)
+ try:
+ filelist = [(f, os.stat(os.path.join(root, workdatestr, f)).st_ctime) \
+ for f in os.listdir(os.path.join(root, workdatestr)) if f.startswith("securitiesNpv")]
+ except OSError:
+ continue
+
+ filelist = sorted(filelist, key = lambda x: x[1], reverse = True)
+ if filelist:
+ file_to_upload = filelist[0][0]
+ newfile_to_upload = file_to_upload
+ if workdate < startdate:
+ newfile_to_upload = "securitiesNpv{0}.csv".format(
+ datetime.datetime.strftime(datetime.datetime.today(), "%Y%m%d_%H%M%S"))
+ # due to the way the drive is mounted, we get an exception when copy
+ # tries to change permissions
+ try:
+ shutil.copy(os.path.join(root, workdatestr, file_to_upload),
+ os.path.join(root, str(startdate), newfile_to_upload))
+ except OSError:
+ pass
+ logging.info("moved file from {0}".format(workdatestr))
+ ftp = FTP('ftp.globeop.com')
+ ftp.login('srntsftp', config.ftp_password)
+ ftp.cwd('incoming')
+ with open(os.path.join(root, str(startdate), newfile_to_upload), "rb") as fh:
+ ftp.storbinary('STOR ' + newfile_to_upload, fh)
+ break
+ logging.info("upload done")
+
if __name__=="__main__":
- if len(sys.argv) > 1:
- workdate = datetime.datetime.strptime(sys.argv[1], "%Y-%m-%d").date()
- else:
- workdate = datetime.date.today()
- logging.basicConfig(filename='/home/share/CorpCDOs/logs/download_daily.log',
+ logging.basicConfig(filename='/home/share/CorpCDOs/logs/globeop.log',
level=logging.INFO,
format='%(asctime)s %(message)s')
- download_data(workdate)
+ def date_from_string(s):
+ return datetime.datetime.strptime(s, "%Y-%m-%d").date()
+ parser = argparse.ArgumentParser()
+ group = parser.add_mutually_exclusive_group(required=True)
+ ## options are technically not exclusive, but we will be running them
+ ## at different times of the day
+ group.add_argument("-d", "--download", action="store_true",
+ help="download reports from GlobeOp")
+ group.add_argument("-u", "--upload", action="store_true",
+ help="upload marks to GlobeOp")
+ parser.add_argument("date", nargs='?', type=date_from_string,
+ default=datetime.date.today())
+ args = parser.parse_args()
+
+ if args.download:
+ download_data(args.date)
+ elif args.upload:
+ upload_data(args.date)
diff --git a/python/upload_daily.py b/python/upload_daily.py
deleted file mode 100644
index 327d5f82..00000000
--- a/python/upload_daily.py
+++ /dev/null
@@ -1,45 +0,0 @@
-import os
-import os.path
-import datetime
-import config
-from ftplib import FTP
-import shutil
-
-if os.name =='nt':
- root = "//WDsentinel/share/Daily"
-elif os.name == 'posix':
- root = '/home/share/Daily'
-
-startdate = datetime.date.today()
-for i in range(10):
- workdate = startdate - datetime.timedelta(days=i)
- workdatestr = str(workdate)
- try:
- filelist = [(f, os.stat(os.path.join(root, workdatestr, f)).st_ctime) \
- for f in os.listdir(os.path.join(root, workdatestr)) if f.startswith("securitiesNpv")]
- except OSError:
- continue
-
- filelist = sorted(filelist, key = lambda x: x[1], reverse = True)
- if filelist:
- file_to_upload = filelist[0][0]
- newfile_to_upload = file_to_upload
- if workdate < startdate:
- newfile_to_upload = "securitiesNpv{0}.csv".format(
- datetime.datetime.strftime(datetime.datetime.today(), "%Y%m%d_%H%M%S"))
- # due to the way the drive is mounted, we get an exception when copy
- # tries to change permissions
- try:
- shutil.copy(os.path.join(root, workdatestr, file_to_upload),
- os.path.join(root, str(startdate), newfile_to_upload))
- except OSError:
- pass
- print("moved file from {0}".format(workdatestr))
- ftp = FTP('ftp.globeop.com')
- ftp.login('srntsftp', config.ftp_password)
- ftp.cwd('incoming')
- with open(os.path.join(root, str(startdate), newfile_to_upload), "rb") as fh:
- ftp.storbinary('STOR ' + newfile_to_upload, fh)
- break
-
-print("done")