エックスサーバでPythonによるWebサービスを行う


エックスサーバでPythonによるWebサービスを行う手順について説明します。
=======================
1,X-serverでサービスを取得する
2,brewをインストール
3,python3.8をインストール
4,Djangoをインストール
5,プロジェクトを作成
6,Webから接続
7,アプリを追加
8,AdminのCSSを有効にする
=======================

1,X-serverでサービスを取得する

https://www.xserver.ne.jp/

はじめにサーバIDを分かりやすい名前を決めて

xxxxxxxxをサーバIDに置き換えてください

chmod 600 xxxxxxxx.key 
ssh -l xxxxxxxx -i xxxxxxxx.key xxxxxxxx.xsrv.jp -p 10022

cat /etc/redhat-release
python -V
python3 -V

2,brewをインストール
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"

echo 'eval $(/home/xxxxxxxx/.linuxbrew/bin/brew shellenv)' >>~/.profile
eval $(/home/xxxxxxxx/.linuxbrew/bin/brew shellenv)

source ~/.profile

brew install gcc
brew doctor

python -V
python3 -V

3,python3.8をインストール
brew install python3

python -V
python3 -V

python3 -m venv env
source env/bin/activate
python -V

4,Djangopyをインストール
pip install --upgrade pip
pip install django==1.11.17

python -m django --version

cd
pwd

5,プロジェクトを作成
django-admin startproject mysite

ls
cd mysite

python manage.py migrate
python manage.py createsuperuser

6,Webから接続
cd
cd xxxxxxxx.xsrv.jp
cd public_html

vi test.html

<html>
<hr>
good!!
<hr>
</html>

http://xxxxxxxx.xsrv.jp/test.html

mkdir top
cd top

ls /home/xxxxxxxx/.linuxbrew/bin/python*

※インストールされたpythonのバージョンにあわせ
 以下の必要な場合はCGI内のパスを変更してください

vi mysite.cgi
i

------------
#!/home/xxxxxxxx/.linuxbrew/bin/python3.8

# encoding: utf-8

import os, sys

sys.path.append("/home/xxxxxxxx/env/lib/python3.8/site-packages")
sys.path.append("/home/xxxxxxxx/env/lib/python3.8/site-packages/django")

sys.path.append("/home/xxxxxxxx/mysite/")

def run_with_cgi(application):

    environ                      = dict(os.environ.items())
    environ['wsgi.input']        = sys.stdin.buffer
    environ['wsgi.errors']       = sys.stderr.buffer
    environ['wsgi.version']      = (1,0)
    environ['wsgi.multithread']  = False
    environ['wsgi.multiprocess'] = True
    environ['wsgi.run_once']     = True
    environ['PATH_INFO']         = environ.get('PATH_INFO',"/") # 追加


    if environ.get('HTTPS','off') in ('on','1'):
        environ['wsgi.url_scheme'] = 'https'
    else:
        environ['wsgi.url_scheme'] = 'http'

    headers_set  = []
    headers_sent = []

    def write(data):
        if not headers_set:
             raise AssertionError("write() before start_response()")

        elif not headers_sent:
             # Before the first output, send the stored headers
             status, response_headers = headers_sent[:] = headers_set
             sys.stdout.buffer.write(('Status: %s\r\n' % status).encode("ascii"))
             for header in response_headers:
                 sys.stdout.buffer.write(('%s: %s\r\n' % header).encode("ascii"))
             sys.stdout.buffer.write(('\r\n').encode("ascii"))

        sys.stdout.buffer.write(data)
        sys.stdout.buffer.flush()

    def start_response(status,response_headers,exc_info=None):
        if exc_info:
            try:
                if headers_sent:
                    # Re-raise original exception if headers sent
                    raise exc_info[0](exc_info[1]).with_traceback(exc_info[2])
            finally:
                exc_info = None     # avoid dangling circular ref
        elif headers_set:
            raise AssertionError("Headers already set!")

        headers_set[:] = [status,response_headers]
        return write

    result = application(environ, start_response)
    try:
        for data in result:
            if data:    # don't send headers until body appears
                write(data)
        if not headers_sent:
            write('')   # send headers now if body was empty
    finally:
        if hasattr(result,'close'):
            result.close()

# Change to the name of your settings module
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

from django.core.wsgi import get_wsgi_application
run_with_cgi(get_wsgi_application())
-------

vi .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.cgi/$1 [QSA,L]

chmod 755 mysite.cgi
chmod 604 .htaccess

http://xxxxxxxx.xsrv.jp/top

cd
cd mysite
cd mysite

vi settings.py

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']

http://xxxxxxxx.xsrv.jp/top

http://xxxxxxxx.xsrv.jp/top/admin

7,アプリを追加

cd ../
python manage.py startapp polls

cd polls

vi views.py
from django.http import HttpResponse


def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

---
vi urls.py

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
]

cd ../
cd mysite
vi urls.py

from django.conf.urls import include

    url(r'^polls/', include('polls.urls', namespace='polls')),

vi settings.py

INSTALLED_APPS = [

    'polls',
]

8,AdminのCSSを有効にする
vi settings.py

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

#STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = './static/'

vi urls.py
----
from django.conf import settings
from django.conf.urls.static import static
from django.views.static import serve
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^admin/([a-xA-Z0-9_]*/)*static/(?P<path>.*)$', serve, {'document_root': settings.STATIC_ROOT}),
]

cd ../
python manage.py collectstatic

vi settings.py

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'ja'

関連ページ

//https://kazusa-pg.com/xserver-django/
//https://note.com/coeeff/n/neab8acfde97e
//https://jurasite.com/post-92
//https://liberal-learner.work/it/diet-record/
//https://www.xserver.ne.jp/manual/man_server_ssh.php

ubuntu 20.04 にOBS StudioとZoomを連携

ubuntu 20.04 にOBS Studioにより、合成した画面でZoom会議に活用

v4l2loopback driverをインストール

sudo apt install v4l2loopback-dkms v4l2loopback-utils
sudo modprobe v4l2loopback devices=1 video_nr=10 card_label="OBS Cam" exclusive_caps=1
sudo apt install cmake qtbase5-dev libobs-dev
sudo apt install git
cd
mkdir myobscode
cd myobscode

git clone --recursive https://github.com/obsproject/obs-studio.git

git clone https://github.com/CatxFish/obs-v4l2sink

cd obs-v4l2sink
mkdir build && cd build
cmake -DLIBOBS_INCLUDE_DIR="../../obs-studio/libobs" -DCMAKE_INSTALL_PREFIX=/usr ..
make -j4
sudo make install

obs-studioをインストールする

sudo apt install obs-studio

cd /usr/lib/x86_64-linux-gnu/obs-plugins
sudo ln -s /usr/lib/obs-plugins/v4l2sink.so 

ツール>V4L2

Path to V4L2 Device

/dev/video10
にする

Zoomをインストールする

sudo snap install zoom-client

参考

//https://www.eigenmagic.com/2020/04/22/how-to-use-obs-studio-with-zoom/
//https://qiita.com/Vermilion_Squadron/items/2e86f239c99dc62ead24
//https://enjoysoftware.hatenablog.com/entry/2019/12/02/144425
//http://www.nofuture.tv/diary/20200413.html
//https://github.com/CatxFish/obs-v4l2sink/issues/52

ubuntu 20.04 pdfファイルを結合する

ubuntu 20.04 で、2つのpdfファイルを結合(つなげて)みた。


input01.pdfとinput02.pdfをつなげてnew01.pdf

pdftk input01.pdf input02.pdf cat out new01.pdf

コマンド 'pdftk' が見つかりません。次の方法でインストールできます:

sudo snap install pdftk       # version 2.02-4, or
sudo apt  install pdftk-java  # version 3.0.9-1

他のバージョンについては 'snap info pdftk' を確認してください。

sudo snap install pdftk

pdftk input01.pdf input02.pdf cat out new01.pdf

つなげることができた

参考

//https://qiita.com/masashi_mizuno_chestnut/items/14c0b877bed7fee0877b
//https://qiita.com/oppminmin/items/1259e74a783aa2ca94b4

検索
Google pdf 結合 ubuntu

ubunt 標準テキストエディタ gedit で並び替え

ubunt 標準テキストエディタのgedit で並び替えが

手軽にできると便利である

方法は、

sannbonnsei

設定は
三本線メニューから
設定>プラグイン(タブ)>並び替え(チェック)

使い方は

並び替え範囲を、カーソルドラッグで指定(シフト十字キー)

編集
並び替え

で、実行できる

参考

//https://kledgeb.blogspot.com/2014/09/ubuntu-gedit-80.html

検索
google ubuntu gedit 並び替え

ubuntu 20.04 に動画字幕作成Vrew をインストール

ubuntu 20.04 に動画字幕作成Vrew をインストールしてみた。

snap
https://snapcraft.io/

で、検索したところVrewが見つかり

sudo snap install vrew --edge

で、インストールしたところ、編集時の音声が出たかった。

このため、直接HPからダウンロードしてみた

https://vrew.voyagerx.com/ja/

https://vrew-files.voyagerx.com/Vrew-0.5.3-x86_64.AppImage

cd
cd ダウンロード

./Vrew-0.5.3-x86_64.AppImage
bash: ./Vrew-0.5.3-x86_64.AppImage: 許可がありません

権限エラーになったので
権限を付与して実行してみる

chmod a+x Vrew-0.5.3-x86_64.AppImage

./Vrew-0.5.3-x86_64.AppImage

無事起動でき、音声をつながった。

とても、いいサービスなので活用してみたいと思う。

ubuntu 20.04 に9vae をインストール

ubuntu 20.04 に9vae をインストールしてみた

公式ページ9VAeきゅうべえアニメ研究所
http://9vae.blogspot.com/p/9vae-download.html

から、Ubuntu版をダウンロード
https://drive.google.com/file/d/0B_jLDEPlHKVjTmU1M05GanZLWjg/view

9vau0704.zip
ダウンロードしたファイルを回答
解答されたファイルを実行

cd 
cd ダウンロード
cd 9vau0704
cd 9va$ 

./9va-pi

./9va-pi: error while loading shared libraries: libgtk-3.so.0: cannot open shared object file: No such file or directory
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
sudo apt-get install lib32z1
sudo apt-get libgtk-3-0:i386

./9va-pi

起動できた。

ホワイトボードアニメーションソフトについて

ホワイトボードに字を書くようなアニメーションサービスを調べてみました。

名称としては

ホワイトボードアニメーション
手書きアニメーション
ホワイトボード風動画
アニメ動画

などと呼ばれている。

サービスとしては

VideoScribe
VYOND
Doodly
Animaker

などがある。

だいたい月額1000円から4000円程度である

文字を手で書くようなイラストの自動生成
画面のズーム、移動、スムーズなページング
部品と背景がセットになった、シーンがいくつかある
アニメキャラクタ、吹き出し、メッセージなど準備

ある程度決まった流れのテンプレートのようである

機能を、もう少し細かくすると

1,てで書きながら文字を表示する
2,画面をズームアップする
3,次の話にするために、横、上、下などにスライドっする
4,画像が横から登場する
5,太い矢印などが表示する
6,吹き出しなどをはじめにだして、文字を表示する
7,重要なところに手で、アンダーラインをつける
8,キャラクターが動く(目、口、手など)
9,吹き出しなどが、小さいところから大きく表示される(ちょっと大きめになって、ほんの少し小さくなる)

などがある

LibreOfficeを使って画像の背景を透明にする

LibreOffice 画像の背景を透明にする手順

libreoffice impress
を、開いて、画像を貼り付ける

画像を選択して
ツール>色の置換
を、選択

一番上の元の色にチェックを入れる
スポイトを、クリックして有効にする
マウスで、背景となる色をクリックする(マウスアイコンは、スポイトにはなりません)
変更する色を、「透過性」のままにして
「置換」を、押す

背景が、透過に変更となる。

色の置換のポップアップ画面を閉じる

画像を選択し
右クリックの「外部ツールで編集」を選択する
横3本線のメニューを開き
名前を付けて保存を選択し
pngで保存する。

Ubuntu 20.04 「VirtualBox COMオブジェクトの確保に失敗しました。アプリケーションを終了します。」

Ubuntu 20.04 で
「VirtualBox COMオブジェクトの確保に失敗しました。アプリケーションを終了します。」
が、表示され起動できなくなった。

格納エリアがいっぱいになったためのようである。

ファイルを外部、HDDに移動したが同様であった。

削除して、インストールしなおしても、同様である。

sudo apt-get remove virtualbox
sudo apt-get install virtualbox

ネットを調べると

//http://ezb4.hateblo.jp/entry/2017/01/23/221635
//https://masablg.blogspot.com/2015/12/virtualbox.html

VirtualBox.xml
を削除して
VirtualBox.xml-prev

VirtualBox.xml
に変更とのこと

VirtualBox.xml
の場所を調べたところ

home/(ユーザネーム)/.config/VirtualBox/VirtualBox.xml-prev

に、あった

複写、上書きしたら、無事起動した。