-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonApplication1.py
78 lines (61 loc) · 2.56 KB
/
PythonApplication1.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
# This program retrieves data from a specific spreadsheet, places it in a CSV file, and prints out information on a specific platform
import gdata.docs.service
import gspread
import codecs
import sys
from getpass import getpass
from platform import Platform
import csv
import os.path
allPlatforms = []
response = ''
if os.path.isfile("platformlist.csv"):
response = raw_input("A CSV file exists. Would you like to use it? (Y/N)")
if response == 'Y' or response == 'y':
f = open('platformlist.csv')
readCSV = csv.reader(f)
for x in readCSV:
print x[0]
allPlatforms.append(Platform(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9]))
elif not os.path.isfile('platformlist.csv') or response == 'n' or response == 'N':
username = raw_input('Enter Google User Name: ')
passwd = getpass('Enter password: ')
print 'authenticating with google...'
# Authenticate using your Google Docs email address and password.
client = gspread.login(username + '@gmail.com', passwd)
# Query the server for the spreadsheet and worksheet
worksheet = client.open("Platform and Media Format Spreadsheet").get_worksheet(4)
print 'organizing worksheet...'
# For the worksheet
platformList = worksheet.get_all_records()
platform_sheet_headers = ['Platform Name',
'Alternate Name',
'Alternate Version',
'Media Formats',
'Operating System (if applicable)',
'Peripherals',
'Sources',
'Exclusion Rational',
'Problematic',
'Notes']
for x in platformList:
print x['Platform Name']
platformObj = Platform(*[x[header] for header in platform_sheet_headers])
allPlatforms.append(platformObj)
# Print all info to csv file
file = open("platformlist.csv", "wb")
wri = csv.writer(file, quoting=csv.QUOTE_ALL)
wri.writerow(platform_sheet_headers)
for x in allPlatforms:
wri.writerow(x.toStringCSV())
# Enter the name of the platform
platformName = raw_input('Enter the name of a platform: ')
# Put the information into a text file named the same as the platform
platformindex = 0
for x in allPlatforms:
if x.platform_name == platformName:
break
else:
platformindex += 1
allPlatforms[platformindex].toFile()
print 'File created'