Skip to content

Commit

Permalink
Merge pull request #26 from colab/adding_catch_exception
Browse files Browse the repository at this point in the history
Catch exceptions using data_importer
  • Loading branch information
MatheusFaria committed Feb 22, 2016
2 parents 77a013c + d884d20 commit fba47f2
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/colab_noosfero/data_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def fetch_communities(self):
json_data = self.get_json_data(url, 1, timestamp=timestamp,
order="updated_at ASC")

if len(json_data) == 0:
if not len(json_data) or not len(json_data.get('communities', [])):
return

json_data = json_data['communities']
Expand All @@ -110,7 +110,11 @@ def fetch_communities(self):

if element['image']:
community.thumb_url = element['image']['thumb_url']
community.save()

try:
community.save()
except:
continue

if 'categories' in element:
self.fetch_community_categories(community,
Expand Down Expand Up @@ -140,27 +144,41 @@ def fetch_software_communities(self):
'NoosferoSoftwareCommunity')
json_data = self.get_json_data(url, 1, timestamp=timestamp,
order="updated_at ASC")

if not len(json_data) or not len(json_data.get('software_infos', [])):
return

json_data = json_data['software_infos']
for element in json_data:
software_communty = NoosferoSoftwareCommunity()
self.fill_object_data(element, software_communty)
software_communty.save()
software_community = NoosferoSoftwareCommunity()
self.fill_object_data(element, software_community)

try:
software_community.save()
except:
continue

self.save_last_update(json_data[-1]['updated_at'],
'NoosferoSoftwareCommunity')

def fetch_articles(self):
url = '/api/v1/articles'
timestamp = TimeStampPlugin.get_last_updated('NoosferoArticle')
json_data = self.get_json_data(url, 1, timestamp=timestamp,
order="updated_at ASC")

if len(json_data) == 0:
if not len(json_data) or not len(json_data.get('articles', [])):
return

json_data = json_data['articles']

for element in json_data:
article = NoosferoArticle()
self.fill_object_data(element, article)
article.save()

try:
article.save()
except:
continue

for category_json in element["categories"]:
category = NoosferoCategory.objects.get_or_create(
Expand Down

0 comments on commit fba47f2

Please sign in to comment.