~ubuntu-app-review-contributors/ubuntu-app-reviews/01

« back to all changes in this revision

Viewing changes to build/lib.linux-i686-2.7/protoborsa_lib/utilities.py

  • Committer: crazycoder
  • Date: 2012-07-06 23:13:09 UTC
  • Revision ID: crazycoder@gmail.com-20120706231309-ngv3mvg06glf7hpf
commit before release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from datetime import datetime;
 
2
from dateutil.relativedelta import relativedelta;
 
3
import os;
 
4
import protoborsaconfig;
 
5
#gets a list and return a dictionary for plotting with pycha.
 
6
'''
 
7
how pycha wants a list of dictionary... for axis ticks: 
 
8
        [{'v': 0, 'label': 'day1'},
 
9
         {'v': 1, 'label': 'day2'},
 
10
         {'v': 2, 'label': 'day3'}]
 
11
'''
 
12
def getAxisTicks(days):
 
13
        ticks = [];
 
14
        i=1;
 
15
        for day in days:
 
16
                if i % 2 != 0:
 
17
                        ticks.append({'v': i, 'label': day});
 
18
                else:
 
19
                        ticks.append({'v': i, 'label': ''});
 
20
                i=i+1;
 
21
        return ticks;
 
22
 
 
23
#2012-05-02
 
24
def getDayMonth(ydate):
 
25
        return ydate[8:10] + '/' + ydate[5:7];
 
26
 
 
27
#format 20120401
 
28
def getLastMonth4YEnd():
 
29
        return (datetime.now() + relativedelta(days=-1)).strftime('%Y%m%d');
 
30
 
 
31
def getLastMonth4YBegin():
 
32
        return (datetime.now() + relativedelta(months=-1,days=-1)).strftime('%Y%m%d');
 
33
 
 
34
def getDbPath():
 
35
        return os.getenv("HOME")+"/.protoborsa/stocksymbols.db";
 
36
 
 
37
def createSettings():
 
38
        settDirectory = os.getenv("HOME")+"/.protoborsa/";
 
39
        dbFile = "stocksymbols.db";
 
40
        destDir = protoborsaconfig.get_data_path() + "/db/" + dbFile;
 
41
 
 
42
        if not os.path.exists(settDirectory):
 
43
                os.makedirs(settDirectory);
 
44
                cmdStr = "cp "+destDir+" "+settDirectory;
 
45
                print "Creating settings directory, copy file there "+cmdStr;
 
46
                os.system(cmdStr);
 
47
        else:
 
48
                print "Dir Exist";
 
49
        fname = settDirectory + "/"+dbFile;
 
50
        if(os.path.isfile(fname)):
 
51
                print "Settings file found";
 
52
                return True;
 
53
        else:
 
54
                print "Settings file non found"+fname;
 
55
                cmdStr = "cp "+destDir+" "+settDirectory;
 
56
                print "Creating settings directory, copy file there "+cmdStr;
 
57
                os.system(cmdStr);
 
58
        return False;