Пример #1
0
    def all_schedules(cls):
        """
        create all xls files and join as one
        """
        def is_dir(di):
            return os.path.isdir(os.path.join(cls.root_dir,di))
        folders = [x for x in os.listdir(cls.root_dir) if is_dir(x)]

        schedules = []
        for f in folders:
            fi = cls(f)
            schedules.append(fi.produce_schedule())
            
        ql = QuickList().union(schedules)
        ql.save("F:\\mp4s\joined.xls")
Пример #2
0
    def tweet(self):
        """
        extract a clip from the pool
        send to twitter and tumblr
        """
        library = os.path.join(os.path.dirname(__file__),
                               "..//libraries//reuse//")
                            
        ql = QuickList().open(os.path.join(library,"pool.xls"))
        
        ql.shuffle()
        
        for r in ql:
            file_loc = os.path.join(library,r["file_name"])
            text = r["nice_title"]
            tags = [
                    r['title'],
                    str(r['year']),
                    "culture reuse"                   
                    ]
            
            name, gif_url = self._upload_gif(file_loc)

            
            #embed_code = "<img class='gfyitem' data-id='JoyfulCircularHamster' />".format(gif_url)
            embed_code = "<img class='gfyitem' data-id='{0}' />".format(name)
            
            tumblr_text = embed_code + '<p>{0}</p><p><a href="{1}">get from gfycat</a></p>'.format(text,gif_url)
            
            tumblr_link = self._tumblr(tumblr_text,tags=tags,keyword=name) #video_url=str(file_loc)
            if tumblr_link:
                text += " {0}".format(tumblr_link)
            tweets = self._tweet_video(text,file_loc)
            
            break
            
        return tweets
Пример #3
0
 def produce_schedule(self):
     """
     moves files and creates a schedule
     """
     destination_path = "F:\\mp4s"
     ql = QuickList()
     ql.header = ["title",
                  "year",
                  "nice_title",
                  "film_ident",
                  "timestamp",
                  "original_name",
                  "file_name",
                  "delete",
                  "trim"]
     
     for x,c in enumerate(self.clips()):
         print c
         old_name = c
         seconds = float(c.replace(".mp4","").replace("clip_",""))
         m, s = divmod(seconds, 60)
         h, m = divmod(m, 60)
         timestamp = "%d:%02d:%02d" % (h, m, s)            
         
         file_name = self.ident + "_{0}.mp4".format(x)
         
         shutil.copyfile(os.path.join(self.clip_dir,old_name),
                         os.path.join(destination_path,file_name))
         
         row = [self.title,
                self.date,
                self.nice_name,
                self.ident,
                timestamp,
                old_name,
                file_name,
                "",
                "",
                ]
         ql.add(row)
         
         
     ql.save(os.path.join(self.dir,"schedule.xls"))
     return ql
Пример #4
0
 def tweet(self):
     
     local_loc = os.path.dirname(__file__)
     storage = QuickList().open(os.path.join(local_loc,
                                             "..//schedules//us-nara-amending-america-dataset-raw-2016-02-25.xls"))
     
     storage.shuffle()
     storage.data = storage.data[:1]
     for r in storage:
         
         if r["year"] and r["title_or_description_from_source"]:
             row = r
             
             desc = row["title_or_description_from_source"]
             """
             remove generic phrasing
             """
             bad_terms=[
                        "Proposing an amendment to the Constitution of the United States relating to ",
                        "Proposing an amendment to the Constitution of the United States",
                        "A joint resolution proposing an amendment to the Constitution of the United States",
                        " to the Constitution of the United States.",
                        "A joint resolution proposing",
                        "A joint resolution proposing an amendment to the Constitution of the United States relative to ",
                        ]
             
             bad_terms.sort(key=lambda x:len(x), reverse=True)
                 
             for b in bad_terms:
                 desc = desc.replace(b,"")
                 
                 
             """
             fix formatting
             """
             desc = desc.strip()    
             if desc[0] == desc[0].lower():
                 desc = desc[0].upper() + desc[1:]
                 
                 
             """
             are we able to provide a link to this?
             """
             
             if row["year"] >= 1973 and row['joint_resolution_number']:
                 link = self.get_amendment_link(row)
                 allowed_length = 141 - 22
             elif row['source_code'] == "A":
                 #link = "book"
                 allowed_length = 141
                 link = None
             else:
                 link = None
                 allowed_length  = 141
                                 
             text  = u"{0} - {1}".format(int(row["year"]),desc)
             
             if len(text) > allowed_length:
                 long_text = text
                 if link == None:
                     #get pastebin version of this and get ready to link it
                     #link = self._paste_to_pastebin(long_text)
                     if link: #pastebin might fail
                         allowed_length = 141 -22
                 text = text[:allowed_length-3] + "..."
                 
             if link:
                 text += " " + link
             
             return self._tweet(text)