This repository has been archived by the owner on Sep 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DB_Datedim.py
67 lines (41 loc) · 1.68 KB
/
DB_Datedim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
!pip install pandas as pd
!pip install numpy as np
!pip install datetime
!pip install os
!pip install requests
import datetime
import os
import requests
# Function that returns a list of yyyMM partitions that are needed to update tables
# in a rolling period set by daysAgo
# for example, to update the last 5 days of data (daysAgo=5)
def get_dtParts(daysAgo):
dtPart = []
startDay = datetime.datetime.now() - datetime.timedelta(days=daysAgo)
endDay = datetime.datetime.now() - datetime.timedelta(days=1)
#creates a list of days between the startDay and endDay
date_list = [startDay + datetime.timedelta(days=x) for x in range(daysAgo)]
#for each date found in date_list, figures out what the yyyyMM format is, and creates a unique list
for dt in date_list:
yyyyMM = int(str(dt)[0:4]+str(dt)[5:7])
if yyyyMM not in dtPart:
dtPart.append(yyyyMM)
return dtPart
def get_etzDates(daysAgo):
startDay = datetime.datetime.now() - datetime.timedelta(days=daysAgo)
endDay = datetime.datetime.now() - datetime.timedelta(days=1)
#creates a list of days between the startDay and endDay
date_list = []
for x in range(daysAgo):
dt = (startDay + datetime.timedelta(days=x)).date()
date_list.append(dt)
return date_list
def get_beginAndEnd(daysAgo):
date_list = []
startDay = datetime.datetime.now() - datetime.timedelta(days=daysAgo)
endDay = datetime.datetime.now() - datetime.timedelta(days=1)
startDay_string = startDay.strftime('%Y-%m-%d')
endDay_string = endDay.strftime('%Y-%m-%d')
date_list.append(startDay_string)
date_list.append(endDay_string)
return date_list