Skip to content

Commit

Permalink
Merge pull request #6 from greyhub/dev_dat_new
Browse files Browse the repository at this point in the history
Dev dat new
  • Loading branch information
greyhub authored Jan 19, 2022
2 parents b68ad79 + 3b44973 commit 6f91e57
Show file tree
Hide file tree
Showing 47 changed files with 337 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ node_modules/
env/
*__pycache__*
.vscode/
calendar_manager/token.json

*client_secret_duy17.json
1 change: 1 addition & 0 deletions calendar_manager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*client_secret_duy17.json
Binary file modified calendar_manager/accounts/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified calendar_manager/accounts/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified calendar_manager/accounts/__pycache__/forms.cpython-38.pyc
Binary file not shown.
Binary file modified calendar_manager/accounts/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file modified calendar_manager/accounts/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified calendar_manager/db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified calendar_manager/events_calendar/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion calendar_manager/events_calendar/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
path("add/member/groupmember/<int:pk>/", add_member_group, name="add_group_member"),
path("remove/member/groupmember/<int:pk>/", remove_member_group, name="remove_member_group"),
path("remove/event/groupevent/<int:pk>/", remove_event_group, name='remove_event_group'),
path("calendar/groupmember/<int:pk>/", GroupCalendarView.as_view(), name="calendar_group_member")
path("calendar/groupmember/<int:pk>/", GroupCalendarView.as_view(), name="calendar_group_member"),
path("connect_google_calendar/", load_data_google_calendar, name="connect_google_calendar")
]
117 changes: 117 additions & 0 deletions calendar_manager/events_calendar/views/Connect_google_calendar.py
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 not shown.
Binary file not shown.
170 changes: 170 additions & 0 deletions calendar_manager/events_calendar/views/fixtures/data.json
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"
}
]
12 changes: 10 additions & 2 deletions calendar_manager/events_calendar/views/other_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
from django.urls import reverse_lazy, reverse
import json
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from events_calendar.views.Connect_google_calendar import connect_google
from events_calendar.models import *
from events_calendar.utils import Calendar
from events_calendar.forms import EventForm, AddMemberForm, AddGroupForm, AddGroupMemberForm, AddGroupEvent, Recommendform
import pandas as pd
from events_calendar.views.pipeline import pipeline
import os

path_to_integration = 'events_calendar/fixtures/event_data.json'
path_to_integration_google = '/home/datdinh/Documents/20211/Tich_ho_he_thong/calendar_manager/google_calendar/data.json'
path_to_integration = 'events_calendar/views/fixtures/event_data.json'
path_to_integration_google = 'events_calendar/views/fixtures/data.json'
path_to_demoData = 'events_calendar/views/data/Demo_data_1.json'
path_to_Data = 'events_calendar/views/data/'
path_to_recommendData = 'events_calendar/views/data/output/suggestion.json'
Expand Down Expand Up @@ -108,6 +109,7 @@ def load_event(request):
)
with open(path_to_integration_google,'w',encoding='utf-8') as f:
json.dump(event_list, f, ensure_ascii=False, indent=4)
print("done")

return HttpResponseRedirect(reverse("events_calendar:calendar"))

Expand Down Expand Up @@ -370,3 +372,9 @@ def export_data_of_group(request, pk):

return render(request, "group_calendar/recommend_calendar.html", {"form": form})

def load_data_google_calendar(request):
connect_google()
print("Access google calendar")
return HttpResponseRedirect(reverse("events_calendar:calendar"))


2 changes: 1 addition & 1 deletion calendar_manager/static/fullcalendar/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# FullCalendar

A full-sized drag & drop JavaScript event calendar
A full-sized drag & drop JavaScript Time Management System

- [Project website and demos](http://fullcalendar.io/)
- [Documentation](http://fullcalendar.io/docs)
Expand Down
6 changes: 3 additions & 3 deletions calendar_manager/templates/accounts/signin.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
{% load static %}
<head>
<title>Sign In | Event Calendar</title>
<title>Sign In | Time Management System</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />

Expand All @@ -20,7 +20,7 @@
<div class="wrap d-md-flex">
<div class="text-wrap p-4 p-lg-5 d-flex img" style="background-image: url({% static 'images/nfj.jpg' %});">
<div class="text w-100">
<h2 class="mb-4">Welcome to Event Calendar</h2>
<h2 class="mb-4">Welcome to Time Management System</h2>
<p>Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</p>
</div>
</div>
Expand Down Expand Up @@ -61,7 +61,7 @@ <h3 class="mb-3 text-center">Signin with this services</h3>
</div>
</form>
<div class="w-100">
<p class="mt-4">New in event calendar? <a href="{% url 'accounts:signup' %}">Sign Up</a></p>
<p class="mt-4">New in Time Management System? <a href="{% url 'accounts:signup' %}">Sign Up</a></p>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 6f91e57

Please sign in to comment.