def filter_data(self, filename): files = glob.glob(filename) if isinstance(filename, str) else filename if not files: return [] last_dt = to_datetime(max(files)) a_month_ago = (last_dt - timedelta(days=30)).date() gmt = pytz.timezone('GMT') local = pytz.timezone('America/Argentina/Buenos_Aires') localize = lambda dt: (gmt.localize(dt)).astimezone(local) in_the_last_month = lambda f: to_datetime(f).date() >= a_month_ago files = filter(in_the_last_month, files) files = self.filter_wrong_sized_data(files) daylight = lambda dt: localize(dt).hour >= 6 and localize(dt).hour <= 20 files = filter(lambda f: daylight(to_datetime(f)), files) return files
def fetch_entries(self): from posts import BlogPost feed_posts = feedparser.parse(self.feed)["items"] for p in feed_posts: if p["id"] not in self.post_id_list: post = BlogPost( email=self.email, title=p["title"], link=p["link"], id_post=p["id"], date_post=to_datetime(p["date_parsed"]), date_updated=to_datetime(p["updated_parsed"]), excerpt=p["summary"], content="", ) post.save()
def filenames_from_a_month_ago(self): path = '/'.join(self.filename.split('/')[:-1]) dt = to_datetime(self.filename) a_month_ago = [] jdb = lambda jd: (dt - timedelta(days=jd)).strftime('%Y.%j') days_before = lambda day: a_month_ago.extend( glob(path + '/*.%s.*.nc' % jdb(day))) days_before(1) return a_month_ago
def fetch_entries(self): from posts import BlogPost print "fetching entries for: %s" % self.name try: feed_posts = feedparser.parse(self.feed)['items'] for p in feed_posts: if p['id'] not in self.post_id_list: dt_published = to_datetime(p['updated_parsed']) if dt_published > self.date_joined: post = BlogPost( email = self.email, title = p['title'], link = p['link'], id_post = p['id'], date_post = dt_published, date_updated = dt_published, excerpt = p['summary'], content = p.get('summary', '') ) post.save() except: print
#! /usr/bin/env python3 from datetime import datetime import helpers print("Time data must be in 24 hrs format!") start = input("Type start time (hh:mm:ss dd-mm-yyyy) -> ").strip() end = input("Type ending time (hh:mm:ss dd-mm-yyyy) -> ").strip() if helpers.is_datetime(start) and helpers.is_datetime(end): try: start_dt = helpers.to_datetime(start) end_dt = helpers.to_datetime(end) if start_dt <= end_dt: wait_time = end_dt - start_dt print(wait_time) else: raise ValueError("Start must not be lower than end.") except ValueError: print("Date is not correct.") else: print("Some date is not correct.")
#! /usr/bin/env python3 import time from datetime import datetime import helpers print("Time data must be in 24 hrs format!") end = input("Type ending time (hh:mm:ss dd-mm-yyyy) -> ").strip() if helpers.is_datetime(end): try: end_dt = helpers.to_datetime(end) now = datetime.now().strftime('%H:%M:%S %d-%m-%Y') now = helpers.to_datetime(now) try: while now <= end_dt: lacks = datetime.now().strftime('%H:%M:%S %d-%m-%Y') lacks = helpers.to_datetime(lacks) print(end_dt - lacks) time.sleep(1) except KeyboardInterrupt: print("Bye!") except ValueError: print("Date is not correct.")