gunicorn settings

This commit is contained in:
Ruidy Nemausat 2019-12-07 13:07:33 +01:00
parent 527e7fd973
commit 1ac8035e7b
6 changed files with 63 additions and 132 deletions

View file

@ -1 +1 @@
{"access_token": "ya29.Il-0B4bh7Yq32B8mvoTT0EiAbYtzr1snXN_AwfcJzzaXu_L74OpPkkH7UgxQIzh3ZkiF_7fQq5VwZ5lIPE8ag5iei_D58rDeFdvT6x3V0MC9uOAyTBsejAlh2aJl9hY1Lg", "client_id": "1068382961407-1dudhnc4e9d7ham53nr6b7ak3c4dlvme.apps.googleusercontent.com", "client_secret": "F9zmMyRRiTUEAMfRiv8A2l1d", "refresh_token": "1//09MUSHKoeusLDCgYIARAAGAkSNwF-L9IrNOqe0TCFB9n1MZZwuAQNtfkdXAv7x4bUs2AxMwfmTdccxSMhCMEwjaXRUD2WR_EXiss", "token_expiry": "2019-12-06T16:13:57Z", "token_uri": "https://accounts.google.com/o/oauth2/token", "user_agent": null, "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "ya29.Il-0B4bh7Yq32B8mvoTT0EiAbYtzr1snXN_AwfcJzzaXu_L74OpPkkH7UgxQIzh3ZkiF_7fQq5VwZ5lIPE8ag5iei_D58rDeFdvT6x3V0MC9uOAyTBsejAlh2aJl9hY1Lg", "expires_in": 3600, "scope": "https://www.googleapis.com/auth/calendar.readonly", "token_type": "Bearer"}, "scopes": ["https://www.googleapis.com/auth/calendar.readonly"], "token_info_uri": "https://oauth2.googleapis.com/tokeninfo", "invalid": false, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}
{"access_token": "ya29.ImC0B6ng8TnZGvS8827TxVZaXax0x25yIjByPGbhAU0piqYLlJMT3w0L3-0Ppz7C9pppOtxS_08ThpN32dqFJUuXKlpftdesbBiohBv9ca7txw3vAisLKAr1-0rW6Yx_ZbU", "client_id": "1068382961407-1dudhnc4e9d7ham53nr6b7ak3c4dlvme.apps.googleusercontent.com", "client_secret": "F9zmMyRRiTUEAMfRiv8A2l1d", "refresh_token": "1//09MUSHKoeusLDCgYIARAAGAkSNwF-L9IrNOqe0TCFB9n1MZZwuAQNtfkdXAv7x4bUs2AxMwfmTdccxSMhCMEwjaXRUD2WR_EXiss", "token_expiry": "2019-12-07T12:37:31Z", "token_uri": "https://accounts.google.com/o/oauth2/token", "user_agent": null, "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "ya29.ImC0B6ng8TnZGvS8827TxVZaXax0x25yIjByPGbhAU0piqYLlJMT3w0L3-0Ppz7C9pppOtxS_08ThpN32dqFJUuXKlpftdesbBiohBv9ca7txw3vAisLKAr1-0rW6Yx_ZbU", "expires_in": 3600, "scope": "https://www.googleapis.com/auth/calendar.readonly", "token_type": "Bearer"}, "scopes": ["https://www.googleapis.com/auth/calendar.readonly"], "token_info_uri": "https://oauth2.googleapis.com/tokeninfo", "invalid": false, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}

View file

@ -5,8 +5,8 @@ services:
image: postgres
web:
build: .
command: bash -c "python manage.py runserver 0.0.0.0:8000"
# command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py loaddata villafleurie.json && gunicorn villafleurie.wsgi 0.0.0.0:8000"
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py loaddata villafleurie.json && python manage.py runserver 0.0.0.0:8000"
# command: gunicorn villafleurie.wsgi -b 0.0.0.0:8000 # Production server more secure
container_name: villafleurie
volumes:
- .:/villafleurie

View file

@ -1,13 +1,16 @@
from __future__ import print_function
from googleapiclient import sample_tools
from google.auth.transport.requests import Request
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
import os.path
import pickle
import datetime
from oauth2client import client
import sys
from googleapiclient import sample_tools
import datetime
# from __future__ import print_function
# from google.auth.transport.requests import Request
# from google_auth_oauthlib.flow import InstalledAppFlow
# from googleapiclient.discovery import build
# import os.path
# import pickle
# from oauth2client import client
# from rental.models import Reservation
@ -30,109 +33,44 @@ def check_availability(place, start_date, end_date):
return True
"""Simple command-line sample for the Calendar API.
Command-line application that retrieves the list of the user's calendars."""
def main1(argv):
# Authenticate and construct service.
"""
Simple command-line sample for the Calendar API.
Command-line application that retrieves the list of the user's calendars."""
service, _ = sample_tools.init(
argv, 'calendar', 'v3', __doc__, __file__,
scope='https://www.googleapis.com/auth/calendar.readonly')
try:
page_token = None
while True:
calendar_list = service.calendarList().list(
pageToken=page_token).execute()
for calendar_list_entry in calendar_list['items']:
print(calendar_list_entry['summary'])
page_token = calendar_list.get('nextPageToken')
calendars = {
'T2': "burik7aclvhc7vsboh06c179uo@group.calendar.google.com",
'T3': "fu7h30p0gk4a2p4nvo7nsbgpok@group.calendar.google.com"
}
if not page_token:
break
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
# Call the Calendar API
calendar_list = service.calendarList().list(
pageToken=page_token).execute()
# print(calendar_list)
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
print('Getting the upcoming 10 T2 arrivals')
events_result = service.events().list(calendarId='burik7aclvhc7vsboh06c179uo@group.calendar.google.com', timeMin=now,
maxResults=10, singleEvents=True,
orderBy='startTime').execute()
for calendar in calendars:
print(f"Upcoming {calendar} events:")
events_result = service.events().list(
calendarId=calendars[calendar],
timeMin=now,
maxResults=10, singleEvents=True,
orderBy='startTime').execute()
events = events_result.get('items', [])
reservation = {}
if not events:
print('No upcoming events found.')
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
end = event['end'].get('dateTime', event['end'].get('date'))
print(start, end, event['summary'])
print('Getting the upcoming 10 T3 arrivals')
events_result = service.events().list(calendarId='fu7h30p0gk4a2p4nvo7nsbgpok@group.calendar.google.com', timeMin=now,
maxResults=10, singleEvents=True,
orderBy='startTime').execute()
events = events_result.get('items', [])
if not events:
print('No upcoming events found.')
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
end = event['end'].get('dateTime', event['end'].get('date'))
print(start, end, event['summary'])
except client.AccessTokenRefreshError:
print('The credentials have been revoked or expired, please re-run'
'the application to re-authorize.')
# If modifying these scopes, delete the file token.pickle.
# SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
# def main():
# """Shows basic usage of the Google Calendar API.
# Prints the start and name of the next 10 events on the user's calendar.
# """
# creds = None
# # The file token.pickle 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.pickle'):
# with open('token.pickle', 'rb') as token:
# creds = pickle.load(token)
# # 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(
# 'credentials.json', SCOPES)
# creds = flow.run_local_server(port=0)
# # Save the credentials for the next run
# with open('token.pickle', 'wb') as token:
# pickle.dump(creds, token)
# service = build('calendar', 'v3', credentials=creds)
# # 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.')
# for event in events:
# start = event['start'].get('dateTime', event['start'].get('date'))
# print(start, event['summary'])
for index, event in enumerate(events):
# start = event['start'].get('dateTime', event['start'].get('date'))
# end = event['end'].get('dateTime', event['end'].get('date'))
# print(start, end, event['summary'])
reservation[index] = {
'place': calendar,
'guest': event['summary'],
'start': event['start'].get('dateTime', event['start'].get('date')),
'end': event['end'].get('dateTime', event['end'].get('date'))
}
print(reservation[index])
if __name__ == '__main__':
main1(sys.argv)
# main()

View file

@ -147,7 +147,7 @@ def calendar(request, place_name):
booked_dates = Reservation.objects.all()
bookings = [
booking for booking in booked_dates if booking.place.name == place_name]
print(place_name)
# print(place_name)
context = {
'place_name': place_name,
'bookings': bookings

View file

@ -1,6 +1,7 @@
asgiref==3.2.3
dj-database-url==0.5.0
Django==3.0
google-api-python-client==1.7.11
Pillow==6.2.1
psycopg2==2.8.4
pytz==2019.3

View file

@ -65,29 +65,29 @@ TEMPLATES = [
WSGI_APPLICATION = 'villafleurie.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'villafleurie',
'USER': 'nemausat',
'PASSWORD': '',
'HOST': '',
'PORT': '5432',
'ATOMIC_REQUESTS': True
}
}
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql',
# 'NAME': 'postgres',
# 'USER': 'postgres',
# 'HOST': 'db',
# 'NAME': 'villafleurie',
# 'USER': 'nemausat',
# 'PASSWORD': '',
# 'HOST': '',
# 'PORT': '5432',
# 'ATOMIC_REQUESTS': True
# }
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': 'db',
'PORT': '5432',
'ATOMIC_REQUESTS': True
}
}
if os.environ.get('ENV') == 'PRODUCTION':
# Heroku
db_from_env = dj_database_url.config(conn_max_age=500)
@ -106,18 +106,10 @@ if os.environ.get('ENV') == 'PRODUCTION':
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', },
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', },
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', },
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', },
]
LANGUAGE_CODE = 'fr'