def handle(self, *args, **options): testmode = False if 1 == len(args) and "testmode" == args[0]: testmode = True self.stdout.write("TEST MODE ON\n\n") elif 0 != len(args): raise CommandError("Invalid argument") self.stdout.write("Updating all series:\n") for s in Series.objects.all(): feeds = s.seriesfeedurl_set.all() ss = None if "FLOSS Weekly" == s.name: ss = FLOSSWeekly(feeds) elif "Sourcetrunk" == s.name: ss = Sourcetrunk(feeds) elif "The Changelog" == s.name: ss = TheChangelog(feeds) else: self.stdout.write("\n\nWarning: Series %s not supported yet!\n" % s.name) continue if testmode: # In test mode, use the sample RSS feeds instead of the real ones ss.testmode() if 0 == len(feeds): self.stdout.write("Skipping series that has no feed...\n") else: self.stdout.write("\n\n- Updating %d feeds for %s" % (len(feeds), s)) for f in ss.feeds: self.stdout.write("\n\n%s (%s): %s" % (f, f.format, f.url)) d = feedparser.parse(f.url) # Check last updated, d["updated"] or d["updated_parsed"] for e in d.entries: self.stdout.write("\n%s:\t" % e.title) # Check if this download is already known entry_link = ss.get_entry_link(e) if 0 != len(ResourceDownloadURL.objects.filter(url=entry_link)): self.stdout.write(u"\u2714") continue self.stdout.write("U") u = ResourceDownloadURL(media_type=f.media_type, format=f.format, url=entry_link) # Get the project's name and the entry's id (project_name, entry_id) = ss.get_project_name_and_entry_id(s, f, e) # Check if this resource is already known try: r = Resource.objects.get(external_id=entry_id) u.resource = r u.save() # The new download url is linked to the # already-existing resource, nothing left to do continue except Resource.DoesNotExist: self.stdout.write(" R") r = Resource( name=e.title, description=e.subtitle_detail.value, url=ss.get_resource_link(e), series=s, status="NW", external_id=entry_id, pub_date=strftime("%Y-%m-%d %H:%M:%S+00:00", e.updated_parsed), ) if e.has_key("itunes_duration"): r.length = e.itunes_duration r.save() # Link the download URL to the resource u.resource = r u.save() # Check if this project is already known try: p = Project.objects.get(name=project_name) # Link the resource to the project r.projects.add(p) continue except Project.DoesNotExist: self.stdout.write(" P") # Project does not exist, create it p = Project(name=project_name, description=e.subtitle_detail.value, status="NW") # Give this project a nice URL only if not yet used # for either a project or a series nu = ss.get_nice_url(project_name) if ( 0 == Project.objects.filter(nice_url=nu).count() and 0 == Series.objects.filter(nice_url=nu).count() ): p.nice_url = nu else: self.stdout.write("\nWarning: nice url '/%s' already in use!\n" % nu) p.save() # Link the resource to the project r.projects.add(p) self.stdout.write("\n")
def handle(self, *args, **options): testmode = False if 1 == len(args) and "testmode" == args[0]: testmode = True self.stdout.write("TEST MODE ON\n\n") elif 0 != len(args): raise CommandError('Invalid argument') self.stdout.write("Updating all series:\n") for s in Series.objects.all(): feeds = s.seriesfeedurl_set.all() ss = None if "FLOSS Weekly" == s.name: ss = FLOSSWeekly(feeds) elif "Sourcetrunk" == s.name: ss = Sourcetrunk(feeds) elif "The Changelog" == s.name: ss = TheChangelog(feeds) else: self.stdout.write( "\n\nWarning: Series %s not supported yet!\n" % s.name) continue if testmode: # In test mode, use the sample RSS feeds instead of the real ones ss.testmode() if 0 == len(feeds): self.stdout.write("Skipping series that has no feed...\n") else: self.stdout.write("\n\n- Updating %d feeds for %s" % (len(feeds), s)) for f in ss.feeds: self.stdout.write("\n\n%s (%s): %s" % (f, f.format, f.url)) d = feedparser.parse(f.url) # Check last updated, d["updated"] or d["updated_parsed"] for e in d.entries: self.stdout.write("\n%s:\t" % e.title) # Check if this download is already known entry_link = ss.get_entry_link(e) if 0 != len( ResourceDownloadURL.objects.filter( url=entry_link)): self.stdout.write(u"\u2714") continue self.stdout.write("U") u = ResourceDownloadURL( media_type=f.media_type, format=f.format, url=entry_link, ) # Get the project's name and the entry's id (project_name, entry_id) = ss.get_project_name_and_entry_id(s, f, e) # Check if this resource is already known try: r = Resource.objects.get(external_id=entry_id) u.resource = r u.save() # The new download url is linked to the # already-existing resource, nothing left to do continue except Resource.DoesNotExist: self.stdout.write(" R") r = Resource( name=e.title, description=e.subtitle_detail.value, url=ss.get_resource_link(e), series=s, status="NW", external_id=entry_id, pub_date=strftime("%Y-%m-%d %H:%M:%S+00:00", e.updated_parsed), ) if e.has_key("itunes_duration"): r.length = e.itunes_duration r.save() # Link the download URL to the resource u.resource = r u.save() # Check if this project is already known try: p = Project.objects.get(name=project_name) # Link the resource to the project r.projects.add(p) continue except Project.DoesNotExist: self.stdout.write(" P") # Project does not exist, create it p = Project(name=project_name, description=e.subtitle_detail.value, status="NW") # Give this project a nice URL only if not yet used # for either a project or a series nu = ss.get_nice_url(project_name) if 0 == Project.objects.filter(nice_url=nu).count() and \ 0 == Series.objects.filter(nice_url=nu).count(): p.nice_url = nu else: self.stdout.write( "\nWarning: nice url '/%s' already in use!\n" % nu) p.save() # Link the resource to the project r.projects.add(p) self.stdout.write("\n")