def __init__(self): super().__init__('tweet_epic') self.parser.add_argument('--now', action='store_true', help="Tweet the next image now") self.epic = EPIC() self.geocoder = GeoNamesGeocoder() self.state = { 'image_queue': {}, 'last_posted_image': datetime(2015, 9, 1), 'last_post_time': datetime(2015, 9, 1) } self.post_interval = timedelta(minutes=60) self.post_interval_fast = timedelta(minutes=45)
def make_animation(): e = EPIC() ENDPOINT = 'http://epic.gsfc.nasa.gov' # get recent images day_before_yesterday = datetime.today() + timedelta(days=-3) recent_images = e.get_recent_images(since=day_before_yesterday) latest_image = recent_images[0]['image'] # only get up to 10 images if len(recent_images) > 10: recent_images = recent_images[:10] # download each image to a temp directory for i, image in enumerate(recent_images): n = str(i).rjust(2, '0') with tempfile.NamedTemporaryFile(dir='tmp/', prefix=f'tmp{n}_', suffix=f'.png', delete=False) as downloadfile: e.download_image(image, downloadfile) # Add annotation to image, resize, rotate annotation = image['image'] os.system(f"convert -resize 800x800 -rotate 180 -fill white -gravity South -pointsize 20 -annotate +0+10 {annotation} {downloadfile.name} {downloadfile.name}") # list of image magick options we want to use for convert to gif animation options = [#'-channel', 'B', '-gamma', '0.90', #'-channel', 'R', '-gamma', '1.03', '-channel', 'RGB', #'-sigmoidal-contrast', '4x5%', '-modulate', '100,130,100', #'-resize', '1000x1000', #'-unsharp', '0x1', #'-rotate', '180', '-delay', '50', '-loop', '0', '-dispose', 'previous'] # put all options into string options_str= '' for element in options: options_str += str(element) + ' ' # combine individual frames into an animated gif os.system(f'convert {options_str} tmp/*.png animation.gif') # remove temporary image frames tmp_files = glob.glob('tmp/*') for f in tmp_files: os.remove(f) return latest_image
def __init__(self): self.log = logging.getLogger(__name__) self.config = ConfigParser.ConfigParser() self.config.read('epictweet.conf') auth = tweepy.OAuthHandler(self.config.get('twitter', 'api_key'), self.config.get('twitter', 'api_secret')) auth.set_access_token(self.config.get('twitter', 'access_key'), self.config.get('twitter', 'access_secret')) self.twitter = tweepy.API(auth) self.epic = EPIC() self.geocoder = GeoNamesGeocoder() self.state = { 'image_queue': {}, 'last_posted_image': datetime(2015, 9, 1), 'last_post_time': datetime(2015, 9, 1) } self.post_interval = timedelta(minutes=80)