Giter Site home page Giter Site logo

thewayiam / tai5-uan5_gian5-gi2_phing5-tai5 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from i3thuan5/tai5-uan5_gian5-gi2_phing5-tai5

0.0 2.0 0.0 3.04 MB

臺灣言語平臺–臺灣母語的語言研究平臺

Home Page: http://hackfoldr.org/tai5-uan5_gian5-gi2_phing5-thai5/

License: MIT License

API Blueprint 5.02% Python 92.93% Gherkin 0.67% Shell 1.39%

tai5-uan5_gian5-gi2_phing5-tai5's Introduction

臺灣言語平臺

Build Status Coverage Status

臺灣言語平臺是母語問答系統的後端主機程式。前端網頁藉由GET/POST,將資料傳來後端主機,主機並以json的格式回傳。

環境設定

virtualenv venv --python python3 # 設置環境檔
sudo apt-get install -y python3 python-virtualenv g++ python3-dev zlib1g-dev libbz2-dev liblzma-dev libboost-all-dev libyaml-dev libxslt1-dev libav-tools libmp3lame0 libavcodec-extra-* # 安裝資料庫的套件 for Ubuntu
sudo apt-get install -y libffi-dev rabbitmq-server # 為了連google oauth2, message queue
. venv/bin/activate # 載入環境
pip install tai5-uan5_gian5-gi2_phing5-tai5
python manage.py migrate #建立資料庫欄位

OSX安裝avconv

設定檔

除了自己臺灣言語平臺的設定外,還需要設定cors的套件django-cors-headersdjango-allauth。 在setting.py最後加上

TIME_ZONE = 'Asia/Taipei'

# 套件設定
INSTALLED_APPS += (
    '臺灣言語資料庫',
    '臺灣言語平臺',
)
MOTHER_TONGUE = '臺灣語言'
FOREIGN_LANGUAGE = '華語'

# 使用者上傳檔案
MEDIA_ROOT = os.path.join(BASE_DIR, "資料庫影音檔案")
MEDIA_URL = '/影音檔案/'

# django-cors-headers
CORS_ORIGIN_REGEX_WHITELIST = ('^.*$', )
CORS_ALLOW_CREDENTIALS = True
INSTALLED_APPS += (
    'corsheaders',
)
MIDDLEWARE_CLASSES += (
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
)

# django-allauth,佮使用者有關係
AUTH_USER_MODEL = '臺灣言語平臺.使用者表'
ACCOUNT_ADAPTER = '臺灣言語平臺.使用者模型.使用者一般接口'
SOCIALACCOUNT_ADAPTER = '臺灣言語平臺.使用者模型.使用者社群接口'
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_UNIQUE_EMAIL = True
SITE_ID = 1
INSTALLED_APPS += (
    # The Django sites framework is required for allauth
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
)
AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    "django.contrib.auth.backends.ModelBackend",
    # `allauth` specific authentication methods, such as login by e-mail
    "allauth.account.auth_backends.AuthenticationBackend",
)
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                # Required by allauth template tags
                'django.contrib.auth.context_processors.auth',
                # `allauth` needs this from django
                'django.template.context_processors.request',
            ],
        },
    },
]
SOCIALACCOUNT_PROVIDERS = {
    'facebook': {
        'SCOPE': ['email', ],
        'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
        'METHOD': 'js_sdk',
        'LOCALE_FUNC': lambda request: 'zh_TW',
        'VERIFIED_EMAIL': False,
        'VERSION': 'v2.3',
    }
}

# celery
# For better celery performance
CELERY_IGNORE_RESULT = True
CELERY_DISABLE_RATE_LIMITS = True
# Only accept json for safety and upcoming celery version default setting
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

from celery.schedules import crontab
CELERY_TIMEZONE = TIME_ZONE
CELERYBEAT_SCHEDULE = {
    '半瞑自sheets掠轉資料庫': {
        'task': '臺灣言語平臺.tasks.半瞑自sheets掠轉資料庫',
        'schedule': crontab(hour=3),
        'args': ()
    },
}

urls.py要加django-allauth臺灣言語平臺影音檔案的路徑,網頁管理介面admin可以需要更改

urlpatterns = [
    url(r'^', include('臺灣言語平臺.網址')),
    url(r'^accounts/', include('allauth.urls')),
    url(r'^影音檔案/(?P<path>.*)$', 'django.views.static.serve', {
        'document_root': settings.MEDIA_ROOT,
    }),
    url(r'^admin/', include(admin.site.urls)),
]

執行服務

需同時開djangocelery workercelery beat三個服務,可用screen

python manage.py runserver

開啟celery worker,負責加資料到Google Sheets

celery -A itaigi worker -l info

開啟celery beat,負責半夜從Google Sheets把正規化的資料抓回來

celery -A itaigi beat -l info

正式服務

可以參考gunicorn來啟動django,取代runserver

匯入資料

請看各專案說定,或參考臺灣言語資料庫的資料匯入

設定FB登入

增加管理員帳號

python manage.py createsuperuser

email密碼隨意輸入

登入管理員並且設定FB app

  1. 用瀏覽器進入 /admin
  2. 輸入剛剛的email密碼
  3. social application
  • provider:FB
  • id:590065061070994
  • key:db4f3fa26d26890e720d17a83ff5a6fe
  • 最後左下角choose all site
  • 其他欄位隨便填

加google sheet編輯資料

設定google development

參考Obtain OAuth2 credentials from Google Developers Console

  1. 申請服務
  2. 開啟Drive API
  3. 用Service Account得到一個服務帳戶json檔案

輸入sheet meta data, 看sheet設定

python manage.py 加sheet的json 服務帳戶json 網址
python manage.py 顯示全部sheet狀態

sheet設定權限給後端

  1. Google Sheets右上角的Share
  2. Can edit處輸入服務帳戶json檔案裡的client_email

開發

環境設定

virtualenv venv --python python3 # 設置環境檔
. venv/bin/activate # 載入環境
pip install -r requirements.txt # 安裝套件
sudo apt-get install -y python3 python-virtualenv g++ python3-dev zlib1g-dev libbz2-dev liblzma-dev libboost-all-dev libyaml-dev libxslt1-dev libav-tools libmp3lame0 libavcodec-extra-* # 安裝資料庫的套件 for Ubuntu
sudo apt-get install -y libffi-dev # 為了連google oauth2

OSX安裝avconv

試驗

python manage.py behave
python manage.py test

人工做將資料對sheet匯入資料庫

python manage.py 整理全部sheet到資料庫

tai5-uan5_gian5-gi2_phing5-tai5's People

Contributors

audreyt avatar pm5 avatar sih4sing5hong5 avatar thewayiam avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.