def check_gcal(event_items): """ Given a bunch of events from gcal, It looks at the time now and finds if it intersects any current events If it does it says you're free at the end of the event, so it will not be accurate if you have 2 back-to-back events. input: 'event_items' : list = events grabbed by rodney at the beginning. output : string = the string that gets sent by rodney over fbchat """ now = int(time.time()) yesterday = rfc.datetimetostr(rfc.now() - timedelta(1)) tomorrow = rfc.datetimetostr(rfc.now() + timedelta(1)) busy = False times = [] for event in event_items: estartts = rfc.strtotimestamp(event["start"]["dateTime"]) eendts = rfc.strtotimestamp(event["end"]["dateTime"]) if estartts < now < eendts: busy = True times.append(estartts) times.append(eendts) print times print busy print now if not busy: return "{0} should be free right now (according to gcal)" else: msg = "{0} is busy right now. He will be free..." free = zip(times[::2], times[1::2]) freestr = [] for (s, e) in free: if s < now < e: estr = time.strftime("%I:%M%p", time.localtime(e)) freestr.append("after {0}.\n".format(estr)) if len(freestr) == 0: msg += "Never :( try sending a text" else: msg += " ".join(freestr) return msg
def lsl(path, hash_name): """ @brief Runs rclone lsjson and builds a Flat. @param path The path to lsjson @param hash_name The hash name to use for the file uid's @param regexs List of compiled regexes, a file path/name that matches any regex will be ignored @return A Flat of files representing the current state of directory at path. """ global track command = ["rclone", "lsjson", "-R", "--files-only", path] subprocess.run(["rclone", "mkdir", path]) result = subprocess.Popen(command + track.rclone_flags, stdout=subprocess.PIPE) list_of_dicts = ujson.load(result.stdout) command = ["rclone", "hashsum", hash_name, path] result = subprocess.Popen(command, stdout=subprocess.PIPE) hashes = {} for file in result.stdout: decode = file.decode(RCLONE_ENCODING).strip() tmp = decode.split(" ", 1) hashes[tmp[1]] = tmp[0] out = Flat(path) for d in list_of_dicts: time = strtotimestamp(d["ModTime"]) hashsize = str(d["Size"]) hash = hashes.get(d["Path"], None) if hash is not None: hashsize += hash else: print(red("ERROR:"), "can't find", d["Path"], "hash") continue out.update(d["Path"], hashsize, time) return out
def date_to_utc_timestamp(date): d = set_tz(date) s = datetimetostr(d) t = strtotimestamp(s) return t
def get_week(publish_date_rfc3339): publish_date = rfc3339.strtotimestamp(publish_date_rfc3339) return int(math.floor((publish_date - sem_start) / week_in_seconds))
import rfc3339 from apiclient.discovery import build from urlparse import urlparse from datetime import datetime # Record script start time script_start = datetime.now() # Google Docs Worksheet Info wks_name = 'Test Spreadsheet' # Semester dates sem_start = '2013-01-28' # Must be a Monday sem_end = '2013-05-05' # Must be a Sunday sem_start = rfc3339.strtotimestamp(sem_start + 'T00:00:00-08:00') sem_end = rfc3339.strtotimestamp(sem_end + 'T23:59:59-07:00') week_in_seconds = 604800 # Convert times to RFC3339 format as required by Blogger API sem_start_rfc3339 = rfc3339.timestamptostr(sem_start) sem_end_rfc3339 = rfc3339.timestamptostr(sem_end) # The private API key is stored in a separate file. api_key = open('private_key.txt').readline() # Returns an instance of an API service object that can be used to make API # calls. The object is constructed with methods specific to the blogger API. # The arguments provided are: # name of the API ('blogger')