def delete_dm(api, dms, logging, testing): num_deleted = 0 try: if logging: log = open(DELETED, "w") for dm in dms: dm.print_info() if not testing: try: api.destroy_direct_message(dm.id) if logging: log.write(dm.text) num_deleted = num_deleted + 1 except TweepError: print_error("Can't delete {0}".format(dm.text)) if logging: log.close() return num_deleted except Exception as e: handle_exception(delete_dm.__name__, e)
def delete_tweets(api, blacklist, testing, logging): num_deleted = 0 try: if logging: log_deleted = open(DELETED, "w") for tweet in blacklist: tweet.print_info() if not testing: try: api.destroy_status(tweet.id) if logging: log_deleted.write(tweet.text) num_deleted = num_deleted + 1 except TweepError: pass if logging: log_deleted.close() return num_deleted except Exception as e: handle_exception(delete_tweets.__name__, e)
def get_instance_of(video_player): try: video_player = video_player.lower() d = { "mplayer": Mplayer(), "omxplayer": OMXplayer() } return d.get(video_player) except Exception as e: handle_exception(e)
def get_instance_of(cipher): try: d = { "base64": Base64(), "binary": Binary(), "baconian": Baconian(), "polybius": PolybiusSquare() } return d.get(cipher) except Exception: e = Exception("{0}(): Class not implemented".format(get_instance_of.__name__)) handle_exception(e)
def get_url(self): try: p = subprocess.Popen(self.name + self.filesystem_options + self.cookie + self.verbosity_options + self.youtube_url, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) p.wait() url, error = p.communicate() if error: handle_error(str(error, ENCODING), False) if url: return str(url.strip(), ENCODING) else: handle_error("Error fetching youtube_url", True) except Exception as e: handle_exception(e)
def parse_archive(): blacklist = [] try: print_info("Parsing archive...") archive = open(ARCHIVE, "r") reader = csv.reader(archive, delimiter=ARCHIVE_DELIMITER, quotechar=ARCHIVE_QUOTECHAR) for row in reader: tweet = Tweet(row[0], row[5]) if tweet.isBlackListed: blacklist.append(tweet) return blacklist except Exception as e: handle_exception(parse_archive.__name__, e)
def play(self, url): try: print_info("Using " + self.name) print_info("Playing {0}".format(url)) command = "{0} \"{1}\"".format(self._get_command(), url) # devnull = open(os.devnull, 'w') p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) p.wait() out, error = p.communicate() if error: handle_error(str(error, ENCODING), False) if out: return str(url.strip(), ENCODING) except Exception as e: handle_exception(e)
def _decrypt(self): e = Exception("{0}(): Method not implemented".format(self.__name__)) handle_exception(e)