| changeset 69 | 3b4a2c79524e |
| parent 66 | 289ded098316 |
| child 72 | ba8ebabbaece |
| 68:17a1c2a67c50 | 69:3b4a2c79524e |
|---|---|
99 |
99 |
100 tag_label_normalized = normalize_tag(tag_label) |
100 tag_label_normalized = normalize_tag(tag_label) |
101 # We get the wikipedia references for the tag_label |
101 # We get the wikipedia references for the tag_label |
102 # We get or create the tag object |
102 # We get or create the tag object |
103 |
103 |
104 tag, created = Tag.objects.get_or_create(label__iexact=tag_label_normalized, defaults={'label':tag_label_normalized, 'original_label':tag_label}) |
104 tag = None |
105 |
105 for t in Tag.objects.filter(label__iexact=tag_label_normalized): |
106 if tag is None or t.url_status != Tag.TAG_URL_STATUS_DICT['null_result']: |
|
107 tag = t |
|
108 if tag.url_status != Tag.TAG_URL_STATUS_DICT['null_result']: |
|
109 break |
|
110 |
|
111 if tag is None: |
|
112 tag = Tag(label=tag_label_normalized, original_label=tag_label) |
|
113 created = True |
|
114 else: |
|
115 created = False |
|
116 |
|
106 site = wiki.Wiki(settings.WIKIPEDIA_API_URL) #@UndefinedVariable |
117 site = wiki.Wiki(settings.WIKIPEDIA_API_URL) #@UndefinedVariable |
107 |
118 |
108 if created: |
119 if created: |
109 wp_res = query_wikipedia_title(site, label=tag_label_normalized) |
120 wp_res = query_wikipedia_title(site, label=tag_label_normalized) |
110 new_label, status, url, pageid, dbpedia_uri, wikipedia_revision_id = wp_res['new_label'], wp_res['status'], wp_res['wikipedia_url'], wp_res['pageid'], wp_res["dbpedia_uri"], wp_res['revision_id'] |
121 new_label, status, url, pageid, dbpedia_uri, wikipedia_revision_id = wp_res['new_label'], wp_res['status'], wp_res['wikipedia_url'], wp_res['pageid'], wp_res["dbpedia_uri"], wp_res['revision_id'] |