-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·122 lines (89 loc) · 3.77 KB
/
main.py
File metadata and controls
executable file
·122 lines (89 loc) · 3.77 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/python3
import optparse
import os
import zipfile
import sys
from collections import defaultdict
from app_store import *
def extractFile(zFile, maxattempts, passwd, filename):
attempts = 0
while attempts < maxattempts:
try:
print("--------Extracting contents from {0}------------------". format(filename))
datafile = zFile.extractall(pwd=passwd)
break
except:
if attempts == 0:
print("Error.")
print("------------------------------Exiting---------------------------------")
exit(2)
attempts_str = 'attempts'
if attempts == 1:
attempts_str == 'attempt'
print("Error. You have {0} {1}". format(attempts, attempts_str))
passwd = input("If the zip file is password protected enter the password otherwise press return: ").strip()
passwd = str.encode(passwd)
if not passwd:
passwd = None
attempts -=1
return datafile
def checkUserInput():
numOfargs = len(sys.argv)
parser = optparse.OptionParser(usage="%prog -f <data filename> -p <zipfile password>")
parser.add_option('-f', dest='dataFile', type='string', help='specifiy the a file (.zip or .csv) to gather data from.' )
parser.add_option('-p','--password', dest='passwd', type='string', help ='password supplied for the zipfile to be looked at.')
(options, args) = parser.parse_args()
dataFile = options.dataFile
passwd = options.passwd
if(passwd == None and dataFile == None and numOfargs > 1):
print(parser.usage)
exit(2)
ShouldPrompt = False
if(dataFile == None):
dataFile = input("Enter the name of the data file to be processed: ")
ShouldPrompt = True
if not os.path.isfile(dataFile):
exitmessage = '[-] ' + str(dataFile) + 'doesn\'t exit.\n'
sys.exit(exitmessage)
if not os.access(dataFile, os.R_OK):
exitmessage= "[-] " + str(dataFile) + " access denied.\n"
sys.exit(exitmessage)
fileExt = os.path.splitext(dataFile)[-1]
maxattempts = 1
if fileExt != '.zip' and fileExt != '.csv':
exitmessage = "[-] Wrong file format.\n"
sys.exit(exitmessage)
else:
if fileExt == '.zip':
zFile = zipfile.ZipFile(dataFile)
if ShouldPrompt == True and passwd == None:
passwd = input("Looks like you provided a zip file, if the zip file is password protected enter the password otherwise press return: ").strip()
passwd = str.encode(passwd)
if not passwd:
passwd = None
if ShouldPrompt == True and passwd == None or passwd != None:
maxattempts = 5
dataFile = extractFile(zFile, maxattempts, passwd, dataFile)
return dataFile
def groupbyratingtotal(datapoint, ratingList):
"""
Classify a datapoint based on rating totals interval and returns an interval where the data point lies
Keyword arguments:
datapoint -- the data point we are considering
ratingList -- a numerical list containing data intervals used for the purposes for classifying
returns a tuple of the min and max interval in which the data point lies
"""
# We are going to assume the list is sorted
prevRate = ratingList[0]
for rateBlock in ratingList[1:]:
if prevRate < datapoint <= rateBlock:
return str(prevRate)+ "-" + str(rateBlock) + " rating count" , True
prevRate = rateBlock
return str(prevRate), False
def main():
#validate the user input
dataFile = checkUserInput()
AppHeader, mobileAppData = readData(dataFile)
#Only consider Apps from the
if __name__ == "__main__":
main()