def checkLastResponse(user, activityURL, applet): from backports.datetime_fromisoformat import MonkeyPatch MonkeyPatch.patch_fromisoformat() expandedApplet = applet a = expandedApplet['activities'][jsonld_expander.reprolibPrefix( activityURL)] activityId = a['_id'].split('/')[1] lastResponse = getSchedule(user)['/'.join( ['applet', str(applet['_id'])])]['/'.join(['activity', str(activityId)])]['lastResponse'] assert isinstance(lastResponse, str) assert len(lastResponse) dtLastResponse = datetime.fromisoformat(lastResponse) assert isinstance(dtLastResponse, datetime) assert dtLastResponse.tzinfo is None tzLastResponse = getSchedule(user, "America/New_York")['/'.join( ['applet', str(applet['_id'])])]['/'.join(['activity', str(activityId)])]['lastResponse'] assert isinstance(tzLastResponse, str) assert len(tzLastResponse) tzdtLastResponse = datetime.fromisoformat(tzLastResponse) assert isinstance(tzdtLastResponse, datetime) assert tzdtLastResponse.tzinfo is not None
def patch_fromisoformat(): if PY_36: # noinspection PyPackageRequirements # noinspection PyUnresolvedReferences from backports.datetime_fromisoformat import MonkeyPatch MonkeyPatch.patch_fromisoformat()
def valid_activity(self, activity, user, project): """ Check validity of activity basing on the the ativity timeslot. Valid if it corresponds to yesterday Args: activity(dict): current activity in iteration user(dict): current user in iteration project(dict): current project in iteration Returns: bool: True if activity is valid else False """ date = activity['time_slot'] # include datetime.fromisoformat support python 3.7+ MonkeyPatch.patch_fromisoformat() activity_date = datetime.fromisoformat(date.replace('Z', '+00:00')).replace(tzinfo=None) user_matches_activity = activity['user_id'] == user['id'] project_matches_activity = project['id'] == activity['project_id'] yesterdays_activity = activity_date >= datetime.combine(Util.yesterday(obj=True), datetime.max.time()) if user_matches_activity and project_matches_activity and yesterdays_activity: return True return False
def get_post_score(post_info): n_comments = len(post_info['comments']) n_likes = len(post_info['liked_by']) n_views = int(post_info['view_count']) if ('view_count' in post_info) else 0 MonkeyPatch.patch_fromisoformat() posted_date = datetime.fromisoformat(post_info['timestamp']) return calculate_score(n_comments, n_likes, n_views, posted_date)
def init_app(self, app): """Flask application initialization.""" self.init_config(app) app.extensions["invenio-madmp"] = self self.auth = HTTPTokenAuth(scheme="Bearer", header="Authorization") self.set_up_rest_auth(app) if not hasattr(datetime, "fromisoformat"): from backports.datetime_fromisoformat import MonkeyPatch MonkeyPatch.patch_fromisoformat()
def __init__(self): """ PostConstruct """ self.configService = None self.appService = None self.xmpp = None self.messageHandler = None MonkeyPatch().patch_fromisoformat()
LGPL2.1. See file COPYING. """ from datetime import datetime, timezone import json import logging import re import sqlite3 from typing import cast, Any, Dict, List, Tuple, Optional, Union log = logging.getLogger(__name__) # Work around missing datetime.fromisoformat for < python3.7 SNAP_DB_TS_FORMAT = '%Y-%m-%dT%H:%M:%S' try: from backports.datetime_fromisoformat import MonkeyPatch MonkeyPatch.patch_fromisoformat() except ImportError: log.debug('backports.datetime_fromisoformat not found') try: # have mypy ignore this line. We use the attribute error to detect if we # have fromisoformat or not ts_parser = datetime.fromisoformat # type: ignore log.debug('found datetime.fromisoformat') except AttributeError: log.info(('Couldn\'t find datetime.fromisoformat, falling back to ' f'static timestamp parsing ({SNAP_DB_TS_FORMAT}')) def ts_parser(data_string: str) -> datetime: # type: ignore try: date = datetime.strptime(data_string, SNAP_DB_TS_FORMAT)
import numpy as np import netCDF4 from termcolor import colored import math from geographiclib.geodesic import Geodesic import sys from backports.datetime_fromisoformat import MonkeyPatch MonkeyPatch.patch_fromisoformat( ) #Hacky solution for Python 3.6 to use ISO format Strings import config_earth """ GFS.py extracts meteorological data from a NOAA netcdf (.nc file) data set. To speed up predicting trajectories, saveNETCDF.py should be run before main.py. This way, the large data set doesn't need to be redownloaded each time the trajectory is run. For now, only wind velocity is used for the simulation prediction. Atmposheric properties such as temperarature and pressure are based off of the U.S. Standard Atmosphere tables from 1976, and the fluids library is used for these, which can be seen in radiation3.py """ class GFS: def __init__(self, centered_coord): # import variables from configuration file self.centered_coord = centered_coord self.min_alt = config_earth.simulation['min_alt'] self.start_time = config_earth.simulation['start_time'] self.hours3 = config_earth.netcdf['hours3'] self.file = netCDF4.Dataset(config_earth.netcdf["nc_file"] ) # Only accepting manual uploads for now self.gfs_time = config_earth.netcdf['nc_start'] self.res = config_earth.netcdf['res']
from flask import Flask, render_template, request, session ,url_for,redirect,flash ,logging ,jsonify,json from flask_mail import Mail, Message from flask_apscheduler import APScheduler from threading import Thread import sqlite3 as sql from functools import wraps from datetime import date,time,datetime,timedelta import calendar_9 # this use for heroku import random import time from backports.datetime_fromisoformat import MonkeyPatch # this use for heroku MonkeyPatch.patch_fromisoformat() # this use for heroku #from passlib.hash import sha256_crypt app = Flask(__name__) DATABASE ='/mdn1.db' app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' ###this part for scheduler scheduler = APScheduler()# scheduler object for reminder email scheduler.init_app(app) # init it whit app scheduler.start() # start to work ##### this part for email sender app.config['MAIL_SERVER']='smtp.gmail.com'
#!/usr/bin/env python3 import subprocess import argparse import os import logging import sys import glob from datetime import datetime if sys.version_info[0] == 3 and sys.version_info[1] < 7: from backports.datetime_fromisoformat import MonkeyPatch MonkeyPatch.patch_fromisoformat() root = os.path.normpath(os.path.join(os.path.dirname(__file__), "..")) logging.basicConfig(level=logging.INFO) logger = logging.getLogger("cibuild") parser = argparse.ArgumentParser(prog="cibuild") general = parser.add_argument_group() general.add_argument("-s", "--snapshots", action="store_true", dest="snapshot", default=False) general.add_argument("-r", "--release", action="store_true", dest="release", default=False) options = parser.parse_args() twine_username = os.environ.get("TWINE_USERNAME") twine_password = os.environ.get("TWINE_PASSWORD") docker_username = os.environ.get("DOCKER_USERNAME") docker_password = os.environ.get("DOCKER_PASSWORD") aws_creds = os.environ.get("AWS_ACCESS_KEY_ID")