Skip to content

Commit 96e1248

Browse files
committed
new
0 parents  commit 96e1248

32 files changed

+953
-0
lines changed

Diff for: db.sqlite3

128 KB
Binary file not shown.

Diff for: func1api/__init__.py

Whitespace-only changes.

Diff for: func1api/__pycache__/__init__.cpython-36.pyc

119 Bytes
Binary file not shown.

Diff for: func1api/__pycache__/__init__.cpython-37.pyc

138 Bytes
Binary file not shown.

Diff for: func1api/__pycache__/admin.cpython-37.pyc

179 Bytes
Binary file not shown.

Diff for: func1api/__pycache__/models.cpython-37.pyc

176 Bytes
Binary file not shown.

Diff for: func1api/__pycache__/views.cpython-36.pyc

1.45 KB
Binary file not shown.

Diff for: func1api/__pycache__/views.cpython-37.pyc

1.63 KB
Binary file not shown.

Diff for: func1api/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

Diff for: func1api/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class Func1ApiConfig(AppConfig):
5+
name = 'func1api'

Diff for: func1api/migrations/__init__.py

Whitespace-only changes.
149 Bytes
Binary file not shown.

Diff for: func1api/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

Diff for: func1api/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

Diff for: func1api/views.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from django.conf import settings
2+
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden
3+
from django.views.decorators.csrf import csrf_exempt
4+
5+
from linebot import LineBotApi, WebhookParser
6+
from linebot.exceptions import InvalidSignatureError, LineBotApiError
7+
from linebot.models import MessageEvent, TextMessage, LocationMessage
8+
from module1 import func
9+
10+
line_bot_api = LineBotApi(settings.LINE_CHANNEL_ACCESS_TOKEN)
11+
parser = WebhookParser(settings.LINE_CHANNEL_SECRET)
12+
13+
@csrf_exempt
14+
def callback(request):
15+
if request.method == 'POST':
16+
signature = request.META['HTTP_X_LINE_SIGNATURE']
17+
body = request.body.decode('utf-8')
18+
try:
19+
events = parser.parse(body, signature)
20+
except InvalidSignatureError:
21+
return HttpResponseForbidden()
22+
except LineBotApiError:
23+
return HttpResponseBadRequest()
24+
25+
for event in events:
26+
if isinstance(event, MessageEvent):
27+
#如果用戶發送文件為訊息文件,回傳函數
28+
if isinstance(event.message, TextMessage):
29+
mtext = event.message.text
30+
if mtext == '@使用說明':
31+
func.sendText(event)
32+
33+
elif mtext == '@最新電影':
34+
func.sendMovie(event)
35+
36+
elif mtext == '@頭條新聞':
37+
func.sendNew(event)
38+
39+
elif mtext == '@抽':
40+
func.sendBeautyImg(event)
41+
42+
elif mtext == '@我已滿18歲':
43+
func.sendSex(event)
44+
45+
elif mtext == "@是否已滿十八歲":
46+
func.sendAdultMenu(event)
47+
48+
elif mtext == '@我未滿18歲':
49+
func.sendNO(event)
50+
else:
51+
mtext == mtext
52+
func.sendOlmi(event)
53+
#如果用戶發送文件為位置訊息,回傳附近美食
54+
if isinstance(event.message, LocationMessage):
55+
func.sendRestaurant(event)
56+
return HttpResponse()
57+
58+
else:
59+
return HttpResponseBadRequest()

Diff for: linebotFunc1/__init__.py

Whitespace-only changes.

Diff for: linebotFunc1/__pycache__/__init__.cpython-36.pyc

123 Bytes
Binary file not shown.

Diff for: linebotFunc1/__pycache__/__init__.cpython-37.pyc

142 Bytes
Binary file not shown.

Diff for: linebotFunc1/__pycache__/settings.cpython-36.pyc

2.53 KB
Binary file not shown.

Diff for: linebotFunc1/__pycache__/settings.cpython-37.pyc

2.57 KB
Binary file not shown.

Diff for: linebotFunc1/__pycache__/urls.cpython-36.pyc

1018 Bytes
Binary file not shown.

Diff for: linebotFunc1/__pycache__/urls.cpython-37.pyc

1.01 KB
Binary file not shown.

Diff for: linebotFunc1/__pycache__/wsgi.cpython-36.pyc

536 Bytes
Binary file not shown.

Diff for: linebotFunc1/__pycache__/wsgi.cpython-37.pyc

555 Bytes
Binary file not shown.

Diff for: linebotFunc1/prod_settings.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .settings import *
2+
STATIC_ROOT = 'staticfiles'
3+
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
4+
ALLOWED_HOSTS = ['*']
5+
DEBUG = False

Diff for: linebotFunc1/settings.py

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
"""
2+
Django settings for linebotFunc1 project.
3+
4+
Generated by 'django-admin startproject' using Django 2.0.5.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/2.0/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = '^9vel$b%l94^ndq(ikfkpsrj6(ky$i9e#gs98(itv0ig+zu^2&'
24+
LINE_CHANNEL_ACCESS_TOKEN = '輸入你的token'
25+
LINE_CHANNEL_SECRET = '輸入你的secret'
26+
27+
# SECURITY WARNING: don't run with debug turned on in production!
28+
DEBUG = False
29+
30+
ALLOWED_HOSTS = ['*']
31+
32+
33+
# Application definition
34+
35+
INSTALLED_APPS = [
36+
'django.contrib.admin',
37+
'django.contrib.auth',
38+
'django.contrib.contenttypes',
39+
'django.contrib.sessions',
40+
'django.contrib.messages',
41+
'django.contrib.staticfiles',
42+
'func1api',
43+
]
44+
45+
MIDDLEWARE = [
46+
'django.middleware.security.SecurityMiddleware',
47+
'django.contrib.sessions.middleware.SessionMiddleware',
48+
'django.middleware.common.CommonMiddleware',
49+
'django.middleware.csrf.CsrfViewMiddleware',
50+
'django.contrib.auth.middleware.AuthenticationMiddleware',
51+
'django.contrib.messages.middleware.MessageMiddleware',
52+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
53+
]
54+
55+
ROOT_URLCONF = 'linebotFunc1.urls'
56+
57+
TEMPLATES = [
58+
{
59+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
60+
'DIRS': [os.path.join(BASE_DIR, 'templates')],
61+
'APP_DIRS': True,
62+
'OPTIONS': {
63+
'context_processors': [
64+
'django.template.context_processors.debug',
65+
'django.template.context_processors.request',
66+
'django.contrib.auth.context_processors.auth',
67+
'django.contrib.messages.context_processors.messages',
68+
],
69+
},
70+
},
71+
]
72+
73+
WSGI_APPLICATION = 'linebotFunc1.wsgi.application'
74+
75+
76+
# Database
77+
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
78+
79+
DATABASES = {
80+
'default': {
81+
'ENGINE': 'django.db.backends.sqlite3',
82+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
83+
}
84+
}
85+
86+
87+
# Password validation
88+
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators
89+
90+
AUTH_PASSWORD_VALIDATORS = [
91+
{
92+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
93+
},
94+
{
95+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
96+
},
97+
{
98+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
99+
},
100+
{
101+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
102+
},
103+
]
104+
105+
106+
# Internationalization
107+
# https://docs.djangoproject.com/en/2.0/topics/i18n/
108+
109+
LANGUAGE_CODE = 'zh-Hant'
110+
111+
TIME_ZONE = 'Asia/Taipei'
112+
113+
USE_I18N = True
114+
115+
USE_L10N = True
116+
117+
USE_TZ = True
118+
119+
120+
# Static files (CSS, JavaScript, Images)
121+
# https://docs.djangoproject.com/en/2.0/howto/static-files/
122+
123+
STATIC_URL = '/static/'
124+
STATICFILES_DIRS = [ #加入 static 路徑
125+
os.path.join(BASE_DIR, 'static'),
126+
]

Diff for: linebotFunc1/urls.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""linebotFunc1 URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/2.0/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.contrib import admin
17+
from django.urls import path
18+
from django.conf.urls import url
19+
from func1api import views
20+
21+
22+
urlpatterns = [
23+
url('^callback', views.callback),
24+
path('admin/', admin.site.urls),
25+
]

Diff for: linebotFunc1/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for linebotFunc1 project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "linebotFunc1.settings")
15+
16+
application = get_wsgi_application()

Diff for: manage.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "linebotFunc1.settings")
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError as exc:
10+
raise ImportError(
11+
"Couldn't import Django. Are you sure it's installed and "
12+
"available on your PYTHONPATH environment variable? Did you "
13+
"forget to activate a virtual environment?"
14+
) from exc
15+
execute_from_command_line(sys.argv)

Diff for: module1/__pycache__/func.cpython-36.pyc

2.41 KB
Binary file not shown.

Diff for: module1/__pycache__/func.cpython-37.pyc

12.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)