Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'arrow' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
cb_log(ev, init, 'Learning generic AIML interactions...')
core.learn(os.sep.join([ev.resource('aiml_files'), '*.aiml']))
cb_log(ev, init, 'Learning properties unique to the client...')
with open(ev.resource('properties.yml')) as prop_file:
prop_data = yaml.safe_load(prop_file)
for prop_key in prop_data:
prop_val = prop_data.get(prop_key)
chatter_core.setBotPredicate(prop_key, prop_val)
cb_log(ev, init, 'Learning additional software details...')
version = ev.bot.info.get_version()
full_version = f'{version.major}.{version.minor}.{version.patch}'
if version.beta:
full_version += ' Beta'
chatter_core.setBotPredicate('version', full_version)
birthday_date = arrow.get(datetime.date(2016, 8, 16))
age = (arrow.utcnow() - birthday_date).days // 365.25
chatter_core.setBotPredicate('age', str(int(age)))
chatter_core.setBotPredicate('birthday', birthday_date.format('MMMM DD'))
chatter_core.setBotPredicate('birthdate', birthday_date.format('MMMM DD, YYYY'))
cb_log(ev, init, 'Loaded Chatter Core.')
def test_publication_date(minimal_record_model, depid_pid, legacyjson_v1):
"""Test publication date."""
for k in ['publication_date', 'embargo_date']:
minimal_record_model[k] = arrow.utcnow().date() - timedelta(days=1)
obj = legacyjson_v1.transform_record(
depid_pid, minimal_record_model)['metadata']
assert arrow.get(obj[k]).date() <= arrow.utcnow().date()
def test_year(self):
result = list(
arrow.Arrow.range(
"year", datetime(2013, 1, 2, 3, 4, 5), datetime(2016, 4, 5, 6, 7, 8)
)
)
self.assertEqual(
result,
[
arrow.Arrow(2013, 1, 2, 3, 4, 5),
arrow.Arrow(2014, 1, 2, 3, 4, 5),
arrow.Arrow(2015, 1, 2, 3, 4, 5),
arrow.Arrow(2016, 1, 2, 3, 4, 5),
],
def test_year(self):
result = list(
arrow.Arrow.span_range("year", datetime(2013, 2, 1), datetime(2016, 3, 31))
)
self.assertEqual(
result,
[
(
arrow.Arrow(2013, 1, 1),
arrow.Arrow(2013, 12, 31, 23, 59, 59, 999999),
),
(
arrow.Arrow(2014, 1, 1),
arrow.Arrow(2014, 12, 31, 23, 59, 59, 999999),
),
(
arrow.Arrow(2015, 1, 1),
arrow.Arrow(2015, 12, 31, 23, 59, 59, 999999),
),
(
arrow.Arrow(2016, 1, 1),
arrow.Arrow(2016, 12, 31, 23, 59, 59, 999999),
),
result = list(
arrow.Arrow.span_range(
"day", datetime(2013, 1, 1, 12), datetime(2013, 1, 4, 12)
)
)
self.assertEqual(
result,
[
(
arrow.Arrow(2013, 1, 1, 0),
arrow.Arrow(2013, 1, 1, 23, 59, 59, 999999),
),
(
arrow.Arrow(2013, 1, 2, 0),
arrow.Arrow(2013, 1, 2, 23, 59, 59, 999999),
),
(
arrow.Arrow(2013, 1, 3, 0),
arrow.Arrow(2013, 1, 3, 23, 59, 59, 999999),
),
(
arrow.Arrow(2013, 1, 4, 0),
arrow.Arrow(2013, 1, 4, 23, 59, 59, 999999),
),
self.assertEqual(arw.shift(weekday=4), arrow.Arrow(2013, 5, 10, 12, 30, 45))
self.assertEqual(arw.shift(weekday=5), arrow.Arrow(2013, 5, 11, 12, 30, 45))
self.assertEqual(arw.shift(weekday=6), arw)
with self.assertRaises(IndexError):
arw.shift(weekday=7)
# Use dateutil.relativedelta's convenient day instances
self.assertEqual(arw.shift(weekday=MO), arrow.Arrow(2013, 5, 6, 12, 30, 45))
self.assertEqual(arw.shift(weekday=MO(0)), arrow.Arrow(2013, 5, 6, 12, 30, 45))
self.assertEqual(arw.shift(weekday=MO(1)), arrow.Arrow(2013, 5, 6, 12, 30, 45))
self.assertEqual(arw.shift(weekday=MO(2)), arrow.Arrow(2013, 5, 13, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TU), arrow.Arrow(2013, 5, 7, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TU(0)), arrow.Arrow(2013, 5, 7, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TU(1)), arrow.Arrow(2013, 5, 7, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TU(2)), arrow.Arrow(2013, 5, 14, 12, 30, 45))
self.assertEqual(arw.shift(weekday=WE), arrow.Arrow(2013, 5, 8, 12, 30, 45))
self.assertEqual(arw.shift(weekday=WE(0)), arrow.Arrow(2013, 5, 8, 12, 30, 45))
self.assertEqual(arw.shift(weekday=WE(1)), arrow.Arrow(2013, 5, 8, 12, 30, 45))
self.assertEqual(arw.shift(weekday=WE(2)), arrow.Arrow(2013, 5, 15, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TH), arrow.Arrow(2013, 5, 9, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TH(0)), arrow.Arrow(2013, 5, 9, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TH(1)), arrow.Arrow(2013, 5, 9, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TH(2)), arrow.Arrow(2013, 5, 16, 12, 30, 45))
self.assertEqual(arw.shift(weekday=FR), arrow.Arrow(2013, 5, 10, 12, 30, 45))
self.assertEqual(arw.shift(weekday=FR(0)), arrow.Arrow(2013, 5, 10, 12, 30, 45))
self.assertEqual(arw.shift(weekday=FR(1)), arrow.Arrow(2013, 5, 10, 12, 30, 45))
self.assertEqual(arw.shift(weekday=FR(2)), arrow.Arrow(2013, 5, 17, 12, 30, 45))
self.assertEqual(arw.shift(weekday=SA), arrow.Arrow(2013, 5, 11, 12, 30, 45))
self.assertEqual(arw.shift(weekday=SA(0)), arrow.Arrow(2013, 5, 11, 12, 30, 45))
self.assertEqual(arw.shift(weekday=SA(1)), arrow.Arrow(2013, 5, 11, 12, 30, 45))
self.assertEqual(arw.shift(weekday=SA(2)), arrow.Arrow(2013, 5, 18, 12, 30, 45))
result = list(
arrow.Arrow.span_range(
"minute", datetime(2013, 1, 1, 0, 0, 30), datetime(2013, 1, 1, 0, 3, 30)
)
)
self.assertEqual(
result,
[
(
arrow.Arrow(2013, 1, 1, 0, 0),
arrow.Arrow(2013, 1, 1, 0, 0, 59, 999999),
),
(
arrow.Arrow(2013, 1, 1, 0, 1),
arrow.Arrow(2013, 1, 1, 0, 1, 59, 999999),
),
(
arrow.Arrow(2013, 1, 1, 0, 2),
arrow.Arrow(2013, 1, 1, 0, 2, 59, 999999),
),
(
arrow.Arrow(2013, 1, 1, 0, 3),
arrow.Arrow(2013, 1, 1, 0, 3, 59, 999999),
),
def test_shift(self):
arw = arrow.Arrow(2013, 5, 5, 12, 30, 45)
self.assertEqual(arw.shift(years=1), arrow.Arrow(2014, 5, 5, 12, 30, 45))
self.assertEqual(arw.shift(quarters=1), arrow.Arrow(2013, 8, 5, 12, 30, 45))
self.assertEqual(
arw.shift(quarters=1, months=1), arrow.Arrow(2013, 9, 5, 12, 30, 45)
)
self.assertEqual(arw.shift(months=1), arrow.Arrow(2013, 6, 5, 12, 30, 45))
self.assertEqual(arw.shift(weeks=1), arrow.Arrow(2013, 5, 12, 12, 30, 45))
self.assertEqual(arw.shift(days=1), arrow.Arrow(2013, 5, 6, 12, 30, 45))
self.assertEqual(arw.shift(hours=1), arrow.Arrow(2013, 5, 5, 13, 30, 45))
self.assertEqual(arw.shift(minutes=1), arrow.Arrow(2013, 5, 5, 12, 31, 45))
self.assertEqual(arw.shift(seconds=1), arrow.Arrow(2013, 5, 5, 12, 30, 46))
self.assertEqual(
arw.shift(microseconds=1), arrow.Arrow(2013, 5, 5, 12, 30, 45, 1)
)
# Remember: Python's weekday 0 is Monday
self.assertEqual(arw.shift(weekday=0), arrow.Arrow(2013, 5, 6, 12, 30, 45))
self.assertEqual(arw.shift(weekday=1), arrow.Arrow(2013, 5, 7, 12, 30, 45))
self.assertEqual(arw.shift(weekday=2), arrow.Arrow(2013, 5, 8, 12, 30, 45))
self.assertEqual(arw.shift(weekday=3), arrow.Arrow(2013, 5, 9, 12, 30, 45))
self.assertEqual(arw.shift(weekday=4), arrow.Arrow(2013, 5, 10, 12, 30, 45))
self.assertEqual(arw.shift(weekday=5), arrow.Arrow(2013, 5, 11, 12, 30, 45))
def test_month(self):
result = list(
arrow.Arrow.range(
"month", datetime(2013, 2, 3, 4, 5, 6), datetime(2013, 5, 6, 7, 8, 9)
)
)
self.assertEqual(
result,
[
arrow.Arrow(2013, 2, 3, 4, 5, 6),
arrow.Arrow(2013, 3, 3, 4, 5, 6),
arrow.Arrow(2013, 4, 3, 4, 5, 6),
arrow.Arrow(2013, 5, 3, 4, 5, 6),
],
self.assertEqual(arw.shift(weekday=TU), arrow.Arrow(2013, 5, 7, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TU(0)), arrow.Arrow(2013, 5, 7, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TU(1)), arrow.Arrow(2013, 5, 7, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TU(2)), arrow.Arrow(2013, 5, 14, 12, 30, 45))
self.assertEqual(arw.shift(weekday=WE), arrow.Arrow(2013, 5, 8, 12, 30, 45))
self.assertEqual(arw.shift(weekday=WE(0)), arrow.Arrow(2013, 5, 8, 12, 30, 45))
self.assertEqual(arw.shift(weekday=WE(1)), arrow.Arrow(2013, 5, 8, 12, 30, 45))
self.assertEqual(arw.shift(weekday=WE(2)), arrow.Arrow(2013, 5, 15, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TH), arrow.Arrow(2013, 5, 9, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TH(0)), arrow.Arrow(2013, 5, 9, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TH(1)), arrow.Arrow(2013, 5, 9, 12, 30, 45))
self.assertEqual(arw.shift(weekday=TH(2)), arrow.Arrow(2013, 5, 16, 12, 30, 45))
self.assertEqual(arw.shift(weekday=FR), arrow.Arrow(2013, 5, 10, 12, 30, 45))
self.assertEqual(arw.shift(weekday=FR(0)), arrow.Arrow(2013, 5, 10, 12, 30, 45))
self.assertEqual(arw.shift(weekday=FR(1)), arrow.Arrow(2013, 5, 10, 12, 30, 45))
self.assertEqual(arw.shift(weekday=FR(2)), arrow.Arrow(2013, 5, 17, 12, 30, 45))
self.assertEqual(arw.shift(weekday=SA), arrow.Arrow(2013, 5, 11, 12, 30, 45))
self.assertEqual(arw.shift(weekday=SA(0)), arrow.Arrow(2013, 5, 11, 12, 30, 45))
self.assertEqual(arw.shift(weekday=SA(1)), arrow.Arrow(2013, 5, 11, 12, 30, 45))
self.assertEqual(arw.shift(weekday=SA(2)), arrow.Arrow(2013, 5, 18, 12, 30, 45))
self.assertEqual(arw.shift(weekday=SU), arw)
self.assertEqual(arw.shift(weekday=SU(0)), arw)
self.assertEqual(arw.shift(weekday=SU(1)), arw)
self.assertEqual(arw.shift(weekday=SU(2)), arrow.Arrow(2013, 5, 12, 12, 30, 45))