-
Notifications
You must be signed in to change notification settings - Fork 149
/
other_functions.py
105 lines (81 loc) · 2.79 KB
/
other_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# encoding: utf-8
# This code is free, THANK YOU!
# It is explained at the guide you can find at www.theincompleteguide.com
# You will also find improvement ideas and explanations
import pandas as pd
import csv, json, time
import os.path
from datetime import datetime
from shutil import copyfile
from scipy.stats import linregress
import numpy as np
import gvars
import requests
from bs4 import BeautifulSoup
import tulipy as ti
def block_thread(logger=False,exception=False,thName='',assName=''):
# this function will lock the thread visually, in case a fatal error happened
while True:
if logger:
logger.info('\n\n\n\n\n\n THREAD %s BLOCKED (%s)\n\n\n\n\n\n' % (thName,assName))
else:
print('\n\n\n\n\n\n THREAD %s BLOCKED (%s)\n\n\n\n\n\n' % (thName,assName))
if exception:
print(str(exception))
time.sleep(10)
def million_to_float(string,scale=False):
try:
string = string.replace('$','')
string = string.replace(',','')
if 'million' in string or 'M' in string:
string = string.strip(' million')
string = string.strip('M')
string = float(string)*1000000
elif 'billion' in string or 'B' in string:
string = string.strip(' billion')
string = string.strip('B')
string = float(string)*1000000000
elif 'trillion' in string or 'T' in string:
string = string.strip(' tillion')
string = string.strip('T')
string = float(string)*1000000000000
elif 'N/A' in string:
string = 0
if scale is 'million':
string = float(string)/1000000
else:
string = float(string)
return round(string,2)
except Exception as e:
print(e)
def create_log_folder(path):
# create the files folder in case it does not exist
if not os.path.exists(gvars.FILES_FOLDER):
os.mkdir(gvars.FILES_FOLDER)
if not os.path.exists(gvars.LOGS_PATH):
os.mkdir(gvars.LOGS_PATH)
folderName = datetime.now().strftime("%Y%m%d_%H%M%S")
path = path + folderName + '/'
if not os.path.exists(path):
os.mkdir(path)
return path
def load_param(param=False):
filePath = gvars.PARAMS_PATH
if not os.path.exists(filePath):
print('ERROR_PP: params file not found at ' + str(filePath))
return False
try:
with open(filePath) as f:
data = json.load(f)
except Exception as e:
print('WARNING_JS: failed to load json file')
print(str(e))
return False
try:
if param:
data = data[param]
return data
except Exception as e:
print('WARNING_PR: params not found at the params file')
print(str(e))
return False