コード例 #1
0
ファイル: classes.py プロジェクト: textandmetal/greg
 def __init__(self, feed, entry, link, filename, title, summary):
     self.feed = feed
     self.link = link
     self.filename = filename
     # self.fullpath = os.path.join(self.directory, self.filename)
     self.title = title.replace("\"", "'")
     self.filename_title = aux.sanitize(title)
     try:
         self.podcasttitle = feed.podcast.title
     except AttributeError:
         self.podcasttitle = feed.name
     try:
         self.sanitizedsubtitle = aux.html_to_text(
             feed.podcast.feed.subtitle)
         if self.sanitizedsubtitle == "":
             self.sanitizedsubtitle = "No description"
     except AttributeError:
         self.sanitizedsubtitle = "No description"
     self.entrysummary = summary
     self.filename_podcasttitle = aux.sanitize(self.podcasttitle)
     self.name = feed.name
     self.date = tuple(entry.linkdate)
コード例 #2
0
ファイル: classes.py プロジェクト: FilipBB/greg
 def __init__(self, feed, entry, link, filename, title, summary):
     self.feed = feed
     self.link = link
     self.filename = filename
     # self.fullpath = os.path.join(self.directory, self.filename)
     self.title = title.replace("\"", "'")
     self.filename_title = aux.sanitize(title)
     try:
         self.podcasttitle = feed.podcast.title
     except AttributeError:
         self.podcasttitle = feed.name
     try:
         self.sanitizedsubtitle = aux.html_to_text(
             feed.podcast.feed.subtitle)
         if self.sanitizedsubtitle == "":
             self.sanitizedsubtitle = "No description"
     except AttributeError:
         self.sanitizedsubtitle = "No description"
     self.entrysummary = summary
     self.filename_podcasttitle = aux.sanitize(self.podcasttitle)
     self.name = feed.name
     self.date = tuple(entry.linkdate)
コード例 #3
0
ファイル: classes.py プロジェクト: textandmetal/greg
 def download_entry(self, entry):
     """
     Find entry link and download entry
     """
     downloadlinks = {}
     downloaded = False
     ignoreenclosures = self.retrieve_config('ignoreenclosures', 'no')
     notype = self.retrieve_config('notype', 'no')
     if ignoreenclosures == 'no':
         for enclosure in entry.enclosures:
             if notype == 'yes':
                 downloadlinks[urlparse(enclosure["href"]).path.split("/")
                               [-1]] = enclosure["href"]
                 # preserve original name
             else:
                 try:
                     # We will download all enclosures of the desired
                     # mime-type
                     if any([
                             mimetype in enclosure["type"]
                             for mimetype in self.mime
                     ]):
                         downloadlinks[urlparse(
                             enclosure["href"]).path.split("/")
                                       [-1]] = enclosure["href"]
                         # preserve original name
                 except KeyError:
                     print(
                         "This podcast carries no information about "
                         "enclosure types. Try using the notype "
                         "option in your greg.conf",
                         file=sys.stderr,
                         flush=True)
     else:
         downloadlinks[urlparse(
             entry.link).query.split("/")[-1]] = entry.link
     for podname in downloadlinks:
         if (podname, entry.linkdate) not in zip(self.entrylinks,
                                                 self.linkdates):
             try:
                 title = entry.title
             except:
                 title = podname
             try:
                 sanitizedsummary = aux.html_to_text(entry.summary)
                 if sanitizedsummary == "":
                     sanitizedsummary = "No summary available"
             except:
                 sanitizedsummary = "No summary available"
             try:
                 placeholders = Placeholders(self, entry,
                                             downloadlinks[podname],
                                             podname, title,
                                             sanitizedsummary)
                 placeholders = aux.check_directory(placeholders)
                 condition = aux.filtercond(placeholders)
                 if condition:
                     print("Downloading {} -- {}".format(title, podname))
                     aux.download_handler(self, placeholders)
                     if self.willtag:
                         aux.tag(placeholders)
                     downloaded = True
                 else:
                     print("Skipping {} -- {}".format(title, podname))
                     downloaded = False
                 if self.info:
                     with open(self.info, 'a') as current:
                         # We write to file this often to ensure that
                         # downloaded entries count as downloaded.
                         current.write(''.join(
                             [podname, ' ',
                              str(entry.linkdate), '\n']))
             except URLError:
                 sys.exit(("... something went wrong. "
                           "Are you connected to the internet?"))
     return downloaded
コード例 #4
0
ファイル: classes.py プロジェクト: FilipBB/greg
 def download_entry(self, entry):
     """
     Find entry link and download entry
     """
     downloadlinks = {}
     downloaded = False
     ignoreenclosures = self.retrieve_config('ignoreenclosures', 'no')
     notype = self.retrieve_config('notype', 'no')
     if ignoreenclosures == 'no':
         for enclosure in entry.enclosures:
             enclosure["href"] = quote(enclosure["href"], safe="%/:=&?~#+!$,;'@()*[]") #Clean up url
             if notype == 'yes':
                 downloadlinks[urlparse(enclosure["href"]).path.split(
                     "/")[-1]] = enclosure["href"]
                 # preserve original name
             else:
                 try:
                     # We will download all enclosures of the desired
                     # mime-type
                     if any([mimetype in enclosure["type"] for mimetype in
                             self.mime]):
                         downloadlinks[urlparse(
                             enclosure["href"]).path.split(
                                 "/")[-1]] = enclosure["href"]
                         # preserve original name
                 except KeyError:
                     print("This podcast carries no information about "
                           "enclosure types. Try using the notype "
                           "option in your greg.conf", file=sys.stderr,
                           flush=True)
     else:
         entry.link = quote(entry.link, safe="%/:=&?~#+!$,;'@()*[]") #Clean up url
         downloadlinks[urlparse(entry.link).query.split(
             "/")[-1]] = entry.link
     for podname in downloadlinks:
         if (podname, entry.linkdate) not in zip(self.entrylinks,
                                                 self.linkdates):
             try:
                 title = entry.title
             except:
                 title = podname
             try:
                 sanitizedsummary = aux.html_to_text(entry.summary)
                 if sanitizedsummary == "":
                     sanitizedsummary = "No summary available"
             except:
                 sanitizedsummary = "No summary available"
             try:
                 placeholders = Placeholders(
                     self, entry, downloadlinks[podname], podname, title,
                     sanitizedsummary)
                 placeholders = aux.check_directory(placeholders)
                 condition = aux.filtercond(placeholders)
                 if condition:
                     print("Downloading {} -- {}".format(title, podname))
                     aux.download_handler(self, placeholders)
                     if self.willtag:
                         aux.tag(placeholders)
                     downloaded = True
                 else:
                     print("Skipping {} -- {}".format(title, podname))
                     downloaded = False
                 if self.info:
                     with open(self.info, 'a') as current:
                         # We write to file this often to ensure that
                         # downloaded entries count as downloaded.
                         current.write(''.join([podname, ' ',
                                       str(entry.linkdate), '\n']))
             except URLError:
                 sys.exit(("... something went wrong. "
                          "Are you connected to the internet?"))
     return downloaded