aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/download_daily.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/python/download_daily.py b/python/download_daily.py
new file mode 100644
index 00000000..6fc14820
--- /dev/null
+++ b/python/download_daily.py
@@ -0,0 +1,54 @@
+import os
+import os.path
+import datetime
+from datetime import date
+from datetime import datetime
+from ftplib import FTP
+import gnupg
+import pdb
+import config
+import pdb
+
+if os.name =='nt':
+ root = "//WDsentinel/share/Daily"
+elif os.name == 'posix':
+ root = '/home/share/Daily'
+
+config
+
+ftp = FTP('ftp.globeop.com')
+ftp.login('srntsftp', config.ftp_password)
+ftp.cwd('outgoing')
+files = ftp.nlst()
+
+workdate = str(datetime.today().date())
+globeopdate = datetime.strftime(datetime.today(), '%Y%m%d')
+
+if not os.path.exists(os.path.join(root, workdate, "Reports")):
+ os.makedirs(os.path.join(root, workdate, "Reports"))
+
+pnlfiles = [filename for filename in files if "csv" in filename and \
+ globeopdate in filename and \
+ "Profit" in filename]
+valuationfiles = [filename for filename in files if "csv" in filename and \
+ globeopdate in filename and \
+ "Valuation" in filename]
+pnlfile = sorted(pnlfiles, reverse=True)[0]
+valuationfile = sorted(valuationfiles, reverse=True)[0]
+
+for filename in [pnlfile, valuationfile]:
+ with open(os.path.join(root, workdate, "Reports", filename), "wb") as fh:
+ ftp.retrbinary('RETR ' + filename, fh.write)
+ print "downloaded {0}".format(filename)
+
+gpg = gnupg.GPG(gnupghome = '/home/guillaume/.gnupg')
+gpg.encoding = 'utf8'
+for filename in [pnlfile, valuationfile]:
+ if "Profit" in filename:
+ newfilename = "Pnl.csv"
+ else:
+ newfilename = "Valuation_Report.csv"
+ with open(os.path.join(root, workdate, "Reports", filename), "rb") as fh:
+ gpg.decrypt_file(fh, output = os.path.join(root, workdate, "Reports", newfilename),
+ passphrase=config.key_password)
+ os.remove(os.path.join(root, workdate, "Reports", filename))