-
Notifications
You must be signed in to change notification settings - Fork 0
/
getDataRemotely.py
39 lines (35 loc) · 1.56 KB
/
getDataRemotely.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
import sys
from dictAsFile_wrapper import *
def run():
hashtableName = 'hashtable.pkl'
data = {}
# use different import based on python version number:
if (sys.version_info > (3, 0)):
# python 3:
if __name__ == '__main__':
print('python 3')
import urllib.request
url = 'https://raw.githubusercontent.com/hchiam/cognateLanguage/master/hashtable.pkl'
urllib.request.urlretrieve(url) # download file
data = readFileToDict(hashtableName)
# with urllib.request.urlopen('https://raw.githubusercontent.com/hchiam/cognateLanguage/master/output_shortlist.txt') as response:
# line = response.readline().decode('utf-8').replace('\n','')
# while line != '':
# data.append(line)
# line = response.readline().decode('utf-8').replace('\n','')
else:
# python 2:
if __name__ == '__main__':
print('python 2')
import urllib2
url = 'https://raw.githubusercontent.com/hchiam/cognateLanguage/master/hashtable.pkl'
response = urllib2.urlopen(url) # download file
data = readFileToDict(hashtableName)
# response = urllib2.urlopen('https://raw.githubusercontent.com/hchiam/cognateLanguage/master/output_shortlist.txt')
# data = response.read().split('\n')
return data
# this if statement is so that the following code only runs if this .py file is not being imported
if __name__ == '__main__':
data = run()
# debug print out:
print ('debug output: data[\"hi\"] = ' + data["hi"])