-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from greyhub/dev_dat_new
Dev dat new
- Loading branch information
Showing
47 changed files
with
337 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ node_modules/ | |
env/ | ||
*__pycache__* | ||
.vscode/ | ||
calendar_manager/token.json | ||
|
||
*client_secret_duy17.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*client_secret_duy17.json |
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/accounts/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/accounts/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/accounts/migrations/__pycache__/0001_initial.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/accounts/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/accounts/views/__pycache__/signin.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/accounts/views/__pycache__/signout.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/accounts/views/__pycache__/signup.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/calendar_manager/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/calendar_manager/__pycache__/settings.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/calendar_manager/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/calendar_manager/__pycache__/views.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/calendar_manager/__pycache__/wsgi.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/events_calendar/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/events_calendar/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/events_calendar/__pycache__/forms.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/events_calendar/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+92 Bytes
(110%)
calendar_manager/events_calendar/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/events_calendar/__pycache__/utils.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/events_calendar/migrations/__pycache__/0001_initial.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/events_calendar/migrations/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
calendar_manager/events_calendar/views/Connect_google_calendar.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
from __future__ import print_function | ||
|
||
import os.path | ||
import os | ||
|
||
import datetime | ||
import pickle | ||
from datetime import timedelta | ||
import datefinder | ||
import json | ||
|
||
from google.auth.transport.requests import Request | ||
from google.oauth2.credentials import Credentials | ||
from google_auth_oauthlib.flow import InstalledAppFlow | ||
from googleapiclient.discovery import build | ||
from googleapiclient.errors import HttpError | ||
from apiclient.discovery import build | ||
from google_auth_oauthlib.flow import InstalledAppFlow | ||
|
||
scopes = ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events.owned', 'https://www.googleapis.com/auth/calendar.readonly'] | ||
|
||
# flow = InstalledAppFlow.from_client_secrets_file("F:\Desktop\THHT_13\calendar_manager\google_calendar\client_secret.json", scopes=scopes) | ||
# credentials = flow.run_console() | ||
|
||
# pickle.dump(credentials, open("token.pkl", "wb")) | ||
# credentials = pickle.load(open("token.pkl", "rb")) | ||
# service = build("calendar", "v3", credentials=credentials) | ||
|
||
def get_token(path_file): | ||
creds = None | ||
# The file token.json stores the user's access and refresh tokens, and is | ||
# created automatically when the authorization flow completes for the first | ||
# time. | ||
if os.path.exists('token.json'): | ||
creds = Credentials.from_authorized_user_file('token.json', scopes) | ||
# If there are no (valid) credentials available, let the user log in. | ||
if not creds or not creds.valid: | ||
if creds and creds.expired and creds.refresh_token: | ||
creds.refresh(Request()) | ||
else: | ||
flow = InstalledAppFlow.from_client_secrets_file( | ||
path_file, scopes) | ||
creds = flow.run_local_server(port=0) | ||
# Save the credentials for the next run | ||
with open('token.json', 'w') as token: | ||
token.write(creds.to_json()) | ||
try: | ||
service = build('calendar', 'v3', credentials=creds) | ||
return service | ||
except HttpError as error: | ||
print('An error occurred: %s' %error) | ||
|
||
|
||
def view_calendar(): | ||
# Call the calendar API | ||
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time | ||
print('Getting the upcoming 10 events') | ||
events_result = service.events().list(calendarId='primary', timeMin=now, maxResults=10, singleEvents=True,orderBy='startTime').execute() | ||
events = events_result.get('items',[]) | ||
|
||
if not events: | ||
print('No upcoming events found.') | ||
return | ||
|
||
# Prints the start and name of the next 10 events | ||
for event in events: | ||
start = event['start'].get('dateTime', event['start'].get('date')) | ||
end_time = event['end'].get('dateTime', event['end'].get('date')) | ||
print(start,end_time,event['summary']) | ||
|
||
|
||
def create_event( service,start_time_str, end_time_str, summary,description=None, location=None): | ||
timezone = 'Asia/Ho_Chi_Minh' | ||
matches_start = list(datefinder.find_dates(start_time_str)) | ||
matches_end = list(datefinder.find_dates(end_time_str)) | ||
if len(matches_start): | ||
start_time = matches_start[0] | ||
end_time = matches_end[0] | ||
|
||
event = { | ||
'summary':summary, | ||
'location':location, | ||
'description': description, | ||
'start':{ | ||
'dateTime': start_time.strftime("%Y-%m-%dT%H:%M:%S"), | ||
'timeZone':'Asia/Ho_Chi_Minh', | ||
}, | ||
'end':{ | ||
'dateTime': end_time.strftime("%Y-%m-%dT%H:%M:%S"), | ||
'timeZone':'Asia/Ho_Chi_Minh', | ||
}, | ||
'reminders':{ | ||
'useDefault':False, | ||
'overrides': [ | ||
{'method': 'email', 'minutes':24*60}, | ||
{'method': 'popup', 'minutes':10}, | ||
], | ||
}, | ||
} | ||
return service.events().insert(calendarId='primary',body=event).execute() | ||
|
||
def connect_google(): | ||
path_file = 'events_calendar/views/infor_user_google/client_secret_duy17.json' | ||
try: | ||
service = get_token(path_file) | ||
event = create_event(service,"15 June 9 PM","15 June 10PM","Tich hop he thong") | ||
print('Event created: %s' % (event.get('htmlLink'))) | ||
|
||
with open('events_calendar/views/fixtures/data.json',encoding='utf-8') as event_data: | ||
data_subjects = json.load(event_data) | ||
for subjects in data_subjects: | ||
event = create_event(service,subjects['start_time_str'],subjects['end_time_str'],subjects['title'],subjects['description']) | ||
print('Event created: %s' % (event.get('htmlLink'))) | ||
|
||
except HttpError as error: | ||
print('An error occurred: %s' %error) | ||
|
Binary file modified
BIN
+0 Bytes
(100%)
calendar_manager/events_calendar/views/__pycache__/event_list.cpython-38.pyc
Binary file not shown.
Binary file modified
BIN
+256 Bytes
(100%)
calendar_manager/events_calendar/views/__pycache__/other_views.cpython-38.pyc
Binary file not shown.
170 changes: 170 additions & 0 deletions
170
calendar_manager/events_calendar/views/fixtures/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
[ | ||
{ | ||
"title": "Phân tích nghiệp vụ", | ||
"description": "IT5031", | ||
"start_time_str": "2021-12-29 12:30:00", | ||
"end_time_str": "2021-12-29 16:30:00" | ||
}, | ||
{ | ||
"title": "Phân tích nghiệp vụ", | ||
"description": "IT5031", | ||
"start_time_str": "2022-01-05 12:30:00", | ||
"end_time_str": "2022-01-05 16:30:00" | ||
}, | ||
{ | ||
"title": "Phân tích nghiệp vụ", | ||
"description": "IT5031", | ||
"start_time_str": "2022-01-12 12:30:00", | ||
"end_time_str": "2022-01-12 16:30:00" | ||
}, | ||
{ | ||
"title": "Phân tích nghiệp vụ", | ||
"description": "IT5031", | ||
"start_time_str": "2022-01-19 12:30:00", | ||
"end_time_str": "2022-01-19 16:30:00" | ||
}, | ||
{ | ||
"title": "IT4868-Khai phá Web", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-03 06:45:00", | ||
"end_time_str": "2022-01-03 10:05:00" | ||
}, | ||
{ | ||
"title": "IT5419-Tích hợp Hệ thống thông tin", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-03 10:15:00", | ||
"end_time_str": "2022-01-03 11:45:00" | ||
}, | ||
{ | ||
"title": "IT4079-Ngôn ngữ và phương pháp dịch", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-04 06:45:00", | ||
"end_time_str": "2022-01-04 09:10:00" | ||
}, | ||
{ | ||
"title": "IT3011-Cấu trúc dữ liệu và thuật toán", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính 03,04-K65C", | ||
"start_time_str": "2022-01-04 15:05:00", | ||
"end_time_str": "2022-01-04 17:30:00" | ||
}, | ||
{ | ||
"title": "IT3080-Mạng máy tính", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K64S", | ||
"start_time_str": "2022-01-05 06:45:00", | ||
"end_time_str": "2022-01-05 09:10:00" | ||
}, | ||
{ | ||
"title": "IT5419-Tích hợp Hệ thống thông tin", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-06 10:15:00", | ||
"end_time_str": "2022-01-06 11:45:00" | ||
}, | ||
{ | ||
"title": "IT4015-Nhập môn an toàn thông tin", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính - KT máy tính-K64C", | ||
"start_time_str": "2022-01-06 14:10:00", | ||
"end_time_str": "2022-01-06 17:30:00" | ||
}, | ||
{ | ||
"title": "IT3080-Mạng máy tính", | ||
"description": "Loại môn học: TN. Tuần học: 7,10,12,14,16. Đối tượng học: IT3080-N06", | ||
"start_time_str": "2022-01-07 15:05:00", | ||
"end_time_str": "2022-01-07 17:30:00" | ||
}, | ||
{ | ||
"title": "IT4868-Khai phá Web", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-10 06:45:00", | ||
"end_time_str": "2022-01-10 10:05:00" | ||
}, | ||
{ | ||
"title": "IT5419-Tích hợp Hệ thống thông tin", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-10 10:15:00", | ||
"end_time_str": "2022-01-10 11:45:00" | ||
}, | ||
{ | ||
"title": "IT4079-Ngôn ngữ và phương pháp dịch", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-11 06:45:00", | ||
"end_time_str": "2022-01-11 09:10:00" | ||
}, | ||
{ | ||
"title": "IT3011-Cấu trúc dữ liệu và thuật toán", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính 03,04-K65C", | ||
"start_time_str": "2022-01-11 15:05:00", | ||
"end_time_str": "2022-01-11 17:30:00" | ||
}, | ||
{ | ||
"title": "IT3080-Mạng máy tính", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K64S", | ||
"start_time_str": "2022-01-12 06:45:00", | ||
"end_time_str": "2022-01-12 09:10:00" | ||
}, | ||
{ | ||
"title": "IT5419-Tích hợp Hệ thống thông tin", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-13 10:15:00", | ||
"end_time_str": "2022-01-13 11:45:00" | ||
}, | ||
{ | ||
"title": "IT4015-Nhập môn an toàn thông tin", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính - KT máy tính-K64C", | ||
"start_time_str": "2022-01-13 14:10:00", | ||
"end_time_str": "2022-01-13 17:30:00" | ||
}, | ||
{ | ||
"title": "IT3080-Mạng máy tính", | ||
"description": "Loại môn học: TN. Tuần học: 7,10,12,14,16. Đối tượng học: IT3080-N06", | ||
"start_time_str": "2022-01-14 15:05:00", | ||
"end_time_str": "2022-01-14 17:30:00" | ||
}, | ||
{ | ||
"title": "IT4868-Khai phá Web", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-17 06:45:00", | ||
"end_time_str": "2022-01-17 10:05:00" | ||
}, | ||
{ | ||
"title": "IT5419-Tích hợp Hệ thống thông tin", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-17 10:15:00", | ||
"end_time_str": "2022-01-17 11:45:00" | ||
}, | ||
{ | ||
"title": "IT4079-Ngôn ngữ và phương pháp dịch", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-18 06:45:00", | ||
"end_time_str": "2022-01-18 09:10:00" | ||
}, | ||
{ | ||
"title": "IT3011-Cấu trúc dữ liệu và thuật toán", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính 03,04-K65C", | ||
"start_time_str": "2022-01-18 15:05:00", | ||
"end_time_str": "2022-01-18 17:30:00" | ||
}, | ||
{ | ||
"title": "IT3080-Mạng máy tính", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K64S", | ||
"start_time_str": "2022-01-19 06:45:00", | ||
"end_time_str": "2022-01-19 09:10:00" | ||
}, | ||
{ | ||
"title": "IT5419-Tích hợp Hệ thống thông tin", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính-K62S", | ||
"start_time_str": "2022-01-20 10:15:00", | ||
"end_time_str": "2022-01-20 11:45:00" | ||
}, | ||
{ | ||
"title": "IT4015-Nhập môn an toàn thông tin", | ||
"description": "Loại môn học: LT+BT. Tuần học: 1-8,10-17. Đối tượng học: KH máy tính - KT máy tính-K64C", | ||
"start_time_str": "2022-01-20 14:10:00", | ||
"end_time_str": "2022-01-20 17:30:00" | ||
}, | ||
{ | ||
"title": "IT3080-Mạng máy tính", | ||
"description": "Loại môn học: TN. Tuần học: 7,10,12,14,16. Đối tượng học: IT3080-N06", | ||
"start_time_str": "2022-01-21 15:05:00", | ||
"end_time_str": "2022-01-21 17:30:00" | ||
} | ||
] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.