forked from mbradac/spreadsheet_parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_tsv_from_spreadsheet.py
More file actions
47 lines (41 loc) · 1.78 KB
/
_tsv_from_spreadsheet.py
File metadata and controls
47 lines (41 loc) · 1.78 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
'''Contains class that provides list getters of data stored in spreadsheets.'''
import csv
import _settings
import _worksheet_downloader
class TsvFromSpreadsheet(object):
def __init__(self):
'''Constructs object that uses for downloading google spreadsheets.
'''
super(TsvFromSpreadsheet, self).__init__()
self.__downloader = _worksheet_downloader.WorksheetDownloader()
def get_contests(self):
'''Returns:
list: List of strings representing contests from spreadsheet.
'''
return self.__get_content(_settings.CONTESTS_ID,
_settings.CONTESTS_GID, _settings.CONTESTS_HEADER_SIZE)
def get_tasks(self):
'''Returns:
list: List of strings representing tasks from spreadsheet.
'''
return self.__get_content(_settings.TASKS_ID,
_settings.TASKS_GID, _settings.TASKS_HEADER_SIZE)
def get_names(self):
'''Returns:
list: List of strings representing names (of rounds, contests, ...)
from spreadsheet.
'''
return self.__get_content(_settings.VALUES_ID, _settings.VALUES_GID,
_settings.VALUES_HEADER_SIZE)
def __get_content(self, content_id, content_gid, header_size):
'''Args:
content_id (str): Key of google spreadsheet (visible in url).
content_gid (str): Gid of sheet of google spreadsheet
(visible in url).
header_size (int): Number of leading rows that will be discarded.
Returns:
list: List of strings from downloaded google spreadsheet.
'''
tsv_content = self.__downloader.download(content_id, content_gid)
rows = list(csv.reader(tsv_content, delimiter='\t'))
return rows[header_size:]