Python arrow.now() Examples
The following are 30
code examples of arrow.now().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
arrow
, or try the search function
.
Example #1
Source File: Inputs_Table_Builder.py From Crypto_Trader with MIT License | 6 votes |
def twitter_sentiment(symbol, max_tweets): """""" now = arrow.now() dates = now.date() print(dates) time = now.time() print(time) sentiment_variables = dates_to_sentiment(dates, symbol, max_tweets) return sentiment_variables ######################################### Split Trading Pair into 'to' and 'from' ###########
Example #2
Source File: summary.py From quantified-self with MIT License | 6 votes |
def check_sleep_time(self): self.slackbot.send_message(text=MsgResource.GOOD_MORNING) record = self.data_handler.read_record() activity = record.get("activity", {}) go_to_bed_time = arrow.get(activity.get("go_to_bed", None)) wake_up_time = arrow.now() self.data_handler.edit_record_with_category( "activity", ("wake_up", str(wake_up_time)) ) sleep_time = (wake_up_time - go_to_bed_time).seconds / 60 / 60 sleep_time = round(sleep_time * 100) / 100 self.data_handler.edit_record(("Sleep", str(sleep_time))) self.slackbot.send_message( text=MsgResource.SLEEP_TIME( bed_time=go_to_bed_time.format("HH:mm"), wakeup_time=wake_up_time.format("HH:mm"), diff_h=str(sleep_time), ) )
Example #3
Source File: server.py From app with MIT License | 6 votes |
def jinja2_filter(app): def format_datetime(value): dt = arrow.get(value) return dt.humanize() app.jinja_env.filters["dt"] = format_datetime @app.context_processor def inject_stage_and_region(): return dict( YEAR=arrow.now().year, URL=URL, SENTRY_DSN=SENTRY_FRONT_END_DSN, VERSION=SHA1, FIRST_ALIAS_DOMAIN=FIRST_ALIAS_DOMAIN, )
Example #4
Source File: test_watson.py From Watson with MIT License | 6 votes |
def test_stop_started_project_at(watson): watson.start('foo') now = arrow.now() # Task can't end before it starts with pytest.raises(WatsonError): time_str = '1970-01-01T00:00' time_obj = arrow.get(time_str) watson.stop(stop_at=time_obj) # Task can't end in the future with pytest.raises(WatsonError): time_str = '2999-12-31T23:59' time_obj = arrow.get(time_str) watson.stop(stop_at=time_obj) watson.stop(stop_at=now) assert watson.frames[-1].stop == now # cancel
Example #5
Source File: test_watson.py From Watson with MIT License | 6 votes |
def test_start_project_at(watson): now = arrow.now() watson.start('foo', start_at=now) watson.stop() # Task can't start before the previous task ends with pytest.raises(WatsonError): time_str = '1970-01-01T00:00' time_obj = arrow.get(time_str) watson.start('foo', start_at=time_obj) # Task can't start in the future with pytest.raises(WatsonError): time_str = '2999-12-31T23:59' time_obj = arrow.get(time_str) watson.start('foo', start_at=time_obj) assert watson.frames[-1].start == now # stop
Example #6
Source File: cron.py From app with MIT License | 6 votes |
def notify_premium_end(): """sent to user who has canceled their subscription and who has their subscription ending soon""" for sub in Subscription.query.filter(Subscription.cancelled == True).all(): if ( arrow.now().shift(days=3).date() > sub.next_bill_date >= arrow.now().shift(days=2).date() ): user = sub.user LOG.d(f"Send subscription ending soon email to user {user}") send_email( user.email, f"Your subscription will end soon {user.name}", render( "transactional/subscription-end.txt", user=user, next_bill_date=sub.next_bill_date.strftime("%Y-%m-%d"), ), render( "transactional/subscription-end.html", user=user, next_bill_date=sub.next_bill_date.strftime("%Y-%m-%d"), ), )
Example #7
Source File: arrow.py From quantified-self with MIT License | 6 votes |
def is_today_day_of_week(day_of_week: list) -> bool: day_of_week = list(map(lambda x: int(x), day_of_week)) if day_of_week == [0]: return True now = arrow.now() today_day_of_week = now.weekday() + 1 if today_day_of_week in day_of_week: return True elif len(day_of_week) == 1: value = day_of_week[0] if value == 8 and ArrowUtil.is_weekday(): return True elif value == 9 and not ArrowUtil.is_weekday(): return True else: return False else: return False
Example #8
Source File: email_handler.py From app with MIT License | 6 votes |
def handle_sender_email(envelope: Envelope): filename = ( arrow.now().format("YYYY-MM-DD_HH-mm-ss") + "_" + random_string(10) + ".eml" ) filepath = os.path.join(SENDER_DIR, filename) with open(filepath, "wb") as f: f.write(envelope.original_content) LOG.d("Write email to sender at %s", filepath) msg = email.message_from_bytes(envelope.original_content) orig = get_orig_message_from_bounce(msg) if orig: LOG.warning( "Original message %s -> %s saved at %s", orig["From"], orig["To"], filepath ) return "250 email to sender accepted"
Example #9
Source File: models.py From app with MIT License | 6 votes |
def _lifetime_or_active_subscription(self) -> bool: """True if user has lifetime licence or active subscription""" if self.lifetime: return True sub: Subscription = self.get_subscription() if sub: return True apple_sub: AppleSubscription = AppleSubscription.get_by(user_id=self.id) if apple_sub and apple_sub.is_valid(): return True manual_sub: ManualSubscription = ManualSubscription.get_by(user_id=self.id) if manual_sub and manual_sub.end_at > arrow.now(): return True return False
Example #10
Source File: base.py From app with MIT License | 6 votes |
def require_api_auth(f): @wraps(f) def decorated(*args, **kwargs): if current_user.is_authenticated: g.user = current_user else: api_code = request.headers.get("Authentication") api_key = ApiKey.get_by(code=api_code) if not api_key: return jsonify(error="Wrong api key"), 401 # Update api key stats api_key.last_used = arrow.now() api_key.times += 1 db.session.commit() g.user = api_key.user return f(*args, **kwargs) return decorated
Example #11
Source File: arrow.py From quantified-self with MIT License | 6 votes |
def is_between(start_time: tuple, end_time: tuple, now=None) -> bool: if start_time is None and end_time is None: return True if now is None: now = datetime.datetime.now() start_h, start_m = start_time end_h, end_m = end_time if end_h == 24 and end_m == 0: end_h = 23 end_m = 59 start = now.replace(hour=start_h, minute=start_m, second=0, microsecond=0) end = now.replace(hour=end_h, minute=end_m, second=0, microsecond=0) if start <= now <= end: return True else: return False
Example #12
Source File: utils.py From iex-api-python with MIT License | 6 votes |
def parse_date(date): """ Parses a date and returns it as YYYYMMDD If not parsable, returns False Args: date """ try: parsed_date = parse(str(date)) except ValueError: return False if (arrow.now().date() - parsed_date.date()).days < 0: raise ValueError("Date cannot be set in the future") return parsed_date.strftime("%Y%m%d") #============# # Validators # #============#
Example #13
Source File: models.py From app with MIT License | 6 votes |
def get_subscription(self) -> "Subscription": """return *active* subscription TODO: support user unsubscribe and re-subscribe """ sub = Subscription.get_by(user_id=self.id) # TODO: sub is active only if sub.next_bill_date > now # due to a bug on next_bill_date, wait until next month (May 8) # when all next_bill_date are correctly updated to add this check if sub and sub.cancelled: # sub is active until the next billing_date + 1 if sub.next_bill_date >= arrow.now().shift(days=-1).date(): return sub # past subscription, user is considered not having a subscription = free plan else: return None else: return sub
Example #14
Source File: cli.py From Watson with MIT License | 6 votes |
def _parse_multiformat(self, value): date = None for fmt in (None, 'HH:mm:ss', 'HH:mm'): try: if fmt is None: date = arrow.get(value) else: date = arrow.get(value, fmt) date = arrow.now().replace( hour=date.hour, minute=date.minute, second=date.second ) break except (ValueError, TypeError): pass return date
Example #15
Source File: data_handler.py From quantified-self with MIT License | 6 votes |
def read_record(self, days=0, date_string=None, redownload=False): date = arrow.now().shift(days=int(days)) if date_string is not None: date = arrow.get(date_string) basename = date.format("YYYY-MM-DD") + ".json" file_path = self.record_path + basename record = self.read_file(file_path) if record is None or redownload is True: year_str = date.format("YYYY") try: self.s3_client.download_file("kino-records", f"{year_str}/{basename}", file_path) except BaseException: return {} return self.read_file(file_path)
Example #16
Source File: watson.py From Watson with MIT License | 6 votes |
def stop(self, stop_at=None): if not self.is_started: raise WatsonError("No project started.") old = self.current if stop_at is None: # One cannot use `arrow.now()` as default argument. Default # arguments are evaluated when a function is defined, not when its # called. Since there might be huge delays between defining this # stop function and calling it, the value of `stop_at` could be # outdated if defined using a default argument. stop_at = arrow.now() if old['start'] > stop_at: raise WatsonError('Task cannot end before it starts.') if stop_at > arrow.now(): raise WatsonError('Task cannot end in the future.') frame = self.frames.add( old['project'], old['start'], stop_at, tags=old['tags'] ) self.current = None return frame
Example #17
Source File: watson.py From Watson with MIT License | 6 votes |
def current(self, value): if not value or 'project' not in value: self._current = {} if self._old_state is None: self._old_state = {} return start = value.get('start', arrow.now()) if not isinstance(start, arrow.Arrow): start = self._parse_date(start) self._current = { 'project': value['project'], 'start': start, 'tags': value.get('tags') or [] } if self._old_state is None: self._old_state = self._current
Example #18
Source File: pipelines.py From aox_proxy_pool with Apache License 2.0 | 6 votes |
def process_item(self, item, spider): if not self.check(item['ip'], item['port']): session = Session() try: session.add( Ip(ip=item['ip'], port=item['port'], http_type=item['http_type'], country=item['country'], create_time=arrow.now().datetime, update_time=arrow.now().datetime)) session.commit() except Exception as e: logging.exception(e) session.rollback() finally: session.close()
Example #19
Source File: models.py From app with MIT License | 6 votes |
def can_upgrade(self): """User who has lifetime licence or giveaway manual subscriptions can decide to upgrade to a paid plan""" sub: Subscription = self.get_subscription() # user who has canceled can also re-subscribe if sub and not sub.cancelled: return False apple_sub: AppleSubscription = AppleSubscription.get_by(user_id=self.id) if apple_sub and apple_sub.is_valid(): return False manual_sub: ManualSubscription = ManualSubscription.get_by(user_id=self.id) # user who has giveaway premium can decide to upgrade if ( manual_sub and manual_sub.end_at > arrow.now() and not manual_sub.is_giveaway ): return False return True
Example #20
Source File: ListFormat.py From topydo with GNU General Public License v3.0 | 6 votes |
def humanize_dates(p_due=None, p_start=None, p_creation=None): """ Returns string with humanized versions of p_due, p_start and p_creation. Examples: - all dates: "16 days ago, due in a month, started 2 days ago" - p_due and p_start: "due in a month, started 2 days ago" - p_creation and p_due: "16 days ago, due in a month" """ dates_list = [] if p_creation: dates_list.append(humanize_date(p_creation)) if p_due: dates_list.append('due ' + humanize_date(p_due)) if p_start: now = arrow.now().date() dates_list.append('{} {}'.format( 'started' if p_start <= now else 'starts', humanize_date(p_start) )) return ', '.join(dates_list)
Example #21
Source File: greylisting.py From app with MIT License | 6 votes |
def greylisting_needed_for_mailbox(alias: Alias) -> bool: min_time = arrow.now().shift(minutes=-1) # get nb of activity on this mailbox nb_activity = ( db.session.query(EmailLog) .join(Contact, EmailLog.contact_id == Contact.id) .join(Alias, Contact.alias_id == Alias.id) .filter(Alias.mailbox_id == alias.mailbox_id, EmailLog.created_at > min_time,) .group_by(EmailLog.id) .count() ) if nb_activity > MAX_ACTIVITY_DURING_MINUTE_PER_MAILBOX: LOG.d( "Too much forward on mailbox %s, alias %s. Nb Activity %s", alias.mailbox, alias, nb_activity, ) return True return False
Example #22
Source File: greylisting.py From app with MIT License | 6 votes |
def greylisting_needed_for_alias(alias: Alias) -> bool: min_time = arrow.now().shift(minutes=-1) # get the nb of activity on this alias nb_activity = ( db.session.query(EmailLog) .join(Contact, EmailLog.contact_id == Contact.id) .filter(Contact.alias_id == alias.id, EmailLog.created_at > min_time,) .group_by(EmailLog.id) .count() ) if nb_activity > MAX_ACTIVITY_DURING_MINUTE_PER_ALIAS: LOG.d( "Too much forward on alias %s. Nb Activity %s", alias, nb_activity, ) return True return False
Example #23
Source File: summary.py From quantified-self with MIT License | 6 votes |
def check_go_to_bed(self): go_to_bed_time = arrow.now() self.data_handler.edit_record_with_category( "activity", ("go_to_bed", str(go_to_bed_time)) ) self.slackbot.send_message(text=MsgResource.GOOD_NIGHT) # slack presence issue # state = State() # state.check() # presence_log = state.current[state.SLEEP] # if presence_log['presence'] == 'away': # go_to_bed_time = arrow.get(presence_log['time']) # self.data_handler.edit_record_with_category( # 'activity', ('go_to_bed', str(go_to_bed_time)))
Example #24
Source File: test_watson.py From Watson with MIT License | 5 votes |
def test_push_with_no_url(watson): config = ConfigParser() config.add_section('backend') config.set('backend', 'token', 'bar') watson.config = config with pytest.raises(WatsonError): watson.push(arrow.now())
Example #25
Source File: test_ill_brw_reqs_patron_loan_extension_actions.py From invenio-app-ils with MIT License | 5 votes |
def test_brwreq_decline_extension_success( client, testdata, json_headers, users ): """Test declone extension success.""" user_login(client, "librarian", users) # create request brwreq, brwreq_pid = _create_on_loan_brwreq_with_pending_extension( "1", client, json_headers ) end_date = brwreq["patron_loan"]["loan"]["end_date"] user_login(client, "librarian", users) # decline extension res = _decline_extension_action(brwreq_pid, dict(), client, json_headers) assert res.status_code == 200 patron_loan = res.get_json()["metadata"]["patron_loan"] assert patron_loan["loan"]["state"] == "ITEM_ON_LOAN" assert "extension_count" not in patron_loan["loan"] assert patron_loan["loan"]["end_date"] == end_date assert patron_loan["extension"]["status"] == "DECLINED" # request again should now fail because it has been declined user_login(client, "patron1", users) res = _request_extension_action(brwreq_pid, client, json_headers) assert res.status_code == 400
Example #26
Source File: listeningthread.py From Tkinter-GUI-Programming-by-Example with MIT License | 5 votes |
def __init__(self, master, user_one, user_two): super().__init__() self.master = master self.user_one = user_one self.user_two = user_two self.requester = Requester() self.running = True self.last_checked_time = arrow.now().timestamp
Example #27
Source File: test_ill_brw_reqs_patron_loan_extension_actions.py From invenio-app-ils with MIT License | 5 votes |
def test_brwreq_request_extension_only_owner( client, testdata, json_headers, users ): """Test that patron can request extension only for his own loan.""" user_login(client, "librarian", users) brwreq, brwreq_pid = _create_on_loan_brwreq_random_dates( "1", client, json_headers ) # anonymous, forbidden user_logout(client) res = _request_extension_action(brwreq_pid, client, json_headers) assert res.status_code == 401 # patron2 is not the owner, forbidden user_login(client, "patron2", users) res = _request_extension_action(brwreq_pid, client, json_headers) assert res.status_code == 403 # patron1 is the owner, success user_login(client, "patron1", users) res = _request_extension_action(brwreq_pid, client, json_headers) assert res.status_code == 200 extension = res.get_json()["metadata"]["patron_loan"]["extension"] assert extension["status"] == "PENDING" assert extension["request_date"] == arrow.now().date().isoformat() # create a new one with patron2 owner, librarian can request extension user_login(client, "librarian", users) brwreq, brwreq_pid = _create_on_loan_brwreq_random_dates( "2", client, json_headers ) res = _request_extension_action(brwreq_pid, client, json_headers) assert res.status_code == 200 assert extension["status"] == "PENDING" assert extension["request_date"] == arrow.now().date().isoformat()
Example #28
Source File: test_watson.py From Watson with MIT License | 5 votes |
def test_push_with_no_token(watson): config = ConfigParser() config.add_section('backend') config.set('backend', 'url', 'http://foo.com') watson.config = config with pytest.raises(WatsonError): watson.push(arrow.now())
Example #29
Source File: patron_loan_actions.py From invenio-app-ils with MIT License | 5 votes |
def validate_loan_start_date(self, value, **kwargs): """Validate loan_start_date field.""" if arrow.get(value).date() < arrow.now().date(): raise ValidationError( _("The loan start date cannot be in the past."), field_names=["loan_start_date"], )
Example #30
Source File: patron_loan_actions.py From invenio-app-ils with MIT License | 5 votes |
def validate_loan_end_date(self, value, **kwargs): """Validate loan_end_date field.""" if arrow.get(value).date() < arrow.now().date(): raise ValidationError( _("The loan end date cannot be in the past."), field_names=["loan_end_date"], )