from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request from googleapiclient.http import MediaIoBaseDownload from html2text import html2text from components import cache, logging from configuration import config SCOPES = [ 'https://www.googleapis.com/auth/drive.metadata.readonly', 'https://www.googleapis.com/auth/drive.readonly' ] logger = logging.setup_logger('google', config.GOOGLE_LOGGING_PATH) creds = None memory_cache = None def auth(): global creds logger.info('auth: called') if creds and creds.valid: return if os.path.exists(config.GOOGLE_AUTH_PATH): with open(config.GOOGLE_AUTH_PATH, 'rb') as token: creds = pickle.load(token)
import json import objc from datetime import datetime, timedelta from dateutil import tz from CalendarStore import CalCalendarStore, CalEvent, CalTask from Cocoa import NSDate from components import cache, logging from configuration import config logger = logging.setup_logger('calendar', config.CALENDAR_LOGGING_PATH) memory_cache = None def fetch_events(request_from_server=False): global memory_cache logger.info('fetch_events: called') if memory_cache: logger.info('fetch_events: checking memory cache') else: logger.info('fetch_events: checking disk cache') memory_cache = cache.fetch(config.CALENDAR_CACHE_PATH) content = cache.content(memory_cache, config.CALENDAR_CACHE_LIFETIME, request_from_server) if content: return content
import json import urllib.request from datetime import datetime import spotipy import spotipy.util as util from spotipy.oauth2 import SpotifyClientCredentials from components import cache, logging from configuration import config logger = logging.setup_logger('spotify', config.SPOTIFY_LOGGING_PATH) sp = None last_downloaded_image_url = None memory_playlists_cache = None destinations_with_image = [] playlist_uri_to_name = {} def auth(): logger.info('auth: called') global sp scope = 'user-read-playback-state user-modify-playback-state playlist-modify-public user-read-currently-playing playlist-read-private playlist-modify-private user-top-read' token = util.prompt_for_user_token( config.SPOTIFY_USERNAME, scope, client_id=config.SPOTIFY_CLIENT_ID, client_secret=config.SPOTIFY_CLIENT_SECRET, redirect_uri=config.SPOTIFY_REDIRECT_URI, cache_path=config.SPOTIFY_AUTH_CACHE_PATH)
import requests from datetime import datetime from components import cache, logging from configuration import config logger = logging.setup_logger('stocks', config.STOCKS_LOGGING_PATH) memory_cache = None def fetch_stocks(force_cache=False): global memory_cache if memory_cache: logger.info('fetch_stocks: checking memory cache') if force_cache: logger.info('fetch_stocks: force cache') return memory_cache[config.CACHE_CONTENT_KEY] content = cache.content(memory_cache, config.STOCKS_CACHE_LIFETIME, False) if content: return content try: logger.info('fetch_stocks: using remote') stocks = [] symbols = config.STOCKS_SYMBOLS for symbol in symbols: stocks.append({ 'name': symbol,
import urllib.request, json from datetime import datetime from components import cache, logging from configuration import config logger = logging.setup_logger( 'lastfm', config.LASTFM_LOGGING_PATH) memory_cache = None def fetch_tracks(request_from_server=False): global memory_cache logger.info('fetch_tracks: called') if memory_cache: logger.info('fetch_tracks: checking memory cache') else: logger.info('fetch_tracks: checking disk cache') memory_cache = cache.fetch(config.LASTFM_CACHE_PATH) content = cache.content(memory_cache, config.LASTFM_CACHE_LIFETIME, request_from_server) if content: return content try: formatted_tracks = [] endpoint = 'https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&period=7day&format=json&limit=5&user='******'&api_key=' + config.LASTFM_API_KEY with urllib.request.urlopen(endpoint) as url: tracks = json.loads(url.read().decode())['toptracks']['track'] for track in tracks: formatted_tracks.append({'name': track['name'], 'count': track['playcount'], 'artist': track['artist']['name']})
import psutil from math import floor from datetime import datetime from subprocess import Popen, PIPE, run from components import cache, logging from configuration import config logger = logging.setup_logger('monitor', config.MONITOR_LOGGING_PATH) memory_cache = None battery_cache = None powermetrics_cache = None def fetch_stats(force_cache=False): global memory_cache logger.info('fetch_stats: called') if memory_cache: logger.info('fetch_stats: checking memory cache') if force_cache: logger.info('fetch_stats: force cache') return memory_cache[config.CACHE_CONTENT_KEY] content = cache.content(memory_cache, config.MONITOR_CACHE_LIFETIME, False) if content: return content formatted_results = { config.MONITOR_CPU_KEY:
import urllib.request import json from datetime import datetime from components import cache, logging from configuration import config logger = logging.setup_logger('theme-park', config.THEME_PARKS_LOGGING_PATH) memory_cache = None def fetch_wait_times(request_from_server=False): global memory_cache logger.info('fetch_wait_times: called') if memory_cache: logger.info('fetch_wait_times: checking memory cache') else: logger.info('fetch_wait_times: checking disk cache') memory_cache = cache.fetch(config.THEME_PARKS_CACHE_PATH) content = cache.content(memory_cache, config.THEME_PARKS_CACHE_LIFETIME, request_from_server) if content: return content rides = [] try: with urllib.request.urlopen(config.THEME_PARKS_DLR_URL) as url: for park_rides in list(json.loads(url.read().decode()).values()): rides.extend(park_rides)
import subprocess from components import applescript, logging from configuration import config logger = logging.setup_logger('displays', config.DISPLAYS_LOGGING_PATH) __was_connected_to_external_display = None def _is_connected_to_external_display(): logger.info('_is_connected_to_external_display: called') result = subprocess.run(['system_profiler', 'SPDisplaysDataType'], stdout=subprocess.PIPE) is_connected_to_external_display = b"Connection Type: DisplayPort" in result.stdout logger.info('_is_connected_to_external_display: result: {}'.format( is_connected_to_external_display)) return is_connected_to_external_display def configure_for_connected_display(): logger.info('configure_for_connected_display: called') global __was_connected_to_external_display is_connected_to_external_display = _is_connected_to_external_display() if __was_connected_to_external_display == is_connected_to_external_display: logger.info('configure_for_connected_display: same state') return else: logger.info('configure_for_connected_display: new state') __was_connected_to_external_display = is_connected_to_external_display