@@ -56,9 +56,10 class Api(): | |||
|
56 | 56 | session = None |
|
57 | 57 | #------------------------------# |
|
58 | 58 | self.url = url |
|
59 | ua = 'CKAN_JRO/2.9.2 (+'+str(self.url)+')' | |
|
59 | #ua = 'CKAN_JRO/2.9.2 (+'+str(self.url)+')' | |
|
60 | self.ua = 'CKAN_JRO/2.9.2 (+http://intranet.igp.gob.pe:8082/DATABASES/ckanext-jro/api-cliente)' | |
|
60 | 61 | #ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' |
|
61 | self.ckan = RemoteCKAN(self.url, apikey=Authorization, user_agent=ua, session=session) | |
|
62 | self.ckan = RemoteCKAN(self.url, apikey=Authorization, user_agent=self.ua, session=session) | |
|
62 | 63 | #self.ckan = RemoteCKAN(self.url, apikey=Authorization) |
|
63 | 64 | self.Authorization = Authorization |
|
64 | 65 | # Change for --> self.separator = os.sep |
@@ -511,4 +512,4 class Api(): | |||
|
511 | 512 | #'search': False, |
|
512 | 513 | #'users': False |
|
513 | 514 | } |
|
514 | return download.dump_things_change(self.ckan, 'datasets', arguments, **kwargs) No newline at end of file | |
|
515 | return download.dump_things_change(self.ckan, 'datasets', arguments, self.ua, **kwargs) No newline at end of file |
@@ -16,7 +16,7 else: | |||
|
16 | 16 | |
|
17 | 17 | DL_CHUNK_SIZE = 100 * 1024 |
|
18 | 18 | |
|
19 | def dump_things_change(ckan, thing, arguments, worker_pool=None, stdout=None, stderr=None, **kwargs): | |
|
19 | def dump_things_change(ckan, thing, arguments, ua, worker_pool=None, stdout=None, stderr=None, **kwargs): | |
|
20 | 20 | if worker_pool is None: |
|
21 | 21 | worker_pool = workers.worker_pool |
|
22 | 22 | if stdout is None: |
@@ -96,7 +96,7 def dump_things_change(ckan, thing, arguments, worker_pool=None, stdout=None, st | |||
|
96 | 96 | filter_url = filtered_urls[record.get('name', '')] |
|
97 | 97 | except: |
|
98 | 98 | filter_url = filtered_urls[record.get('id', '')] |
|
99 | create_datapackage_change(record, filter_url, datapackage_dir, stderr, arguments['--apikey'], arguments['--remote'], arguments['--insecure']) | |
|
99 | create_datapackage_change(record, filter_url, datapackage_dir, stderr, arguments['--apikey'], arguments['--remote'], arguments['--insecure'], ua) | |
|
100 | 100 | |
|
101 | 101 | while expecting_number in results: |
|
102 | 102 | record = results.pop(expecting_number) |
@@ -108,7 +108,7 def dump_things_change(ckan, thing, arguments, worker_pool=None, stdout=None, st | |||
|
108 | 108 | if 'interrupt' in errors: |
|
109 | 109 | return 2 |
|
110 | 110 | |
|
111 | def create_datapackage_change(record, filtered_url, datapackage_dir, stderr, apikey, host_url, insecure): | |
|
111 | def create_datapackage_change(record, filtered_url, datapackage_dir, stderr, apikey, host_url, insecure, ua): | |
|
112 | 112 | resource_formats_to_ignore = ['API', 'api'] |
|
113 | 113 | |
|
114 | 114 | os.makedirs(os.path.join(datapackage_dir, 'data')) |
@@ -129,7 +129,7 def create_datapackage_change(record, filtered_url, datapackage_dir, stderr, api | |||
|
129 | 129 | filename = name_no_repetition(resource['name'], os.path.join(datapackage_dir, 'data'), 'resource') |
|
130 | 130 | resource['path'] = os.path.join(datapackage_dir, 'data', filename) |
|
131 | 131 | |
|
132 | cres = create_resource_change(resource, stderr, apikey, host_url, insecure) | |
|
132 | cres = create_resource_change(resource, stderr, apikey, host_url, insecure, ua) | |
|
133 | 133 | if not cres: |
|
134 | 134 | continue |
|
135 | 135 | ''' |
@@ -153,14 +153,14 def create_datapackage_change(record, filtered_url, datapackage_dir, stderr, api | |||
|
153 | 153 | |
|
154 | 154 | return datapackage_dir, datapackage, json_path |
|
155 | 155 | |
|
156 | def create_resource_change(resource, stderr, apikey, host_url, insecure): | |
|
156 | def create_resource_change(resource, stderr, apikey, host_url, insecure, ua): | |
|
157 | 157 | # ---------- REPLACE URL --------- # |
|
158 | 158 | if urlparse(host_url).netloc != 'www.igp.gob.pe' and urlparse(resource['url']).netloc == 'www.igp.gob.pe': |
|
159 | 159 | resource['url'] = resource['url'].replace(urlparse(resource['url']).scheme + '://' + urlparse(resource['url']).netloc, |
|
160 | 160 | urlparse(host_url).scheme + '://' + urlparse(host_url).netloc) |
|
161 | 161 | #----------------------------------# |
|
162 | 162 | try: |
|
163 | r = requests.get(resource['url'], headers={'Authorization': apikey}, stream=True, verify=not insecure) | |
|
163 | r = requests.get(resource['url'], headers={'Authorization': apikey, 'User-Agent': ua}, stream=True, verify=not insecure) | |
|
164 | 164 | #---------------------------------------# |
|
165 | 165 | try: |
|
166 | 166 | r.raise_for_status() |
General Comments 0
You need to be logged in to leave comments.
Login now