lynx   »   [go: up one dir, main page]

ラベル poetry の投稿を表示しています。 すべての投稿を表示
ラベル poetry の投稿を表示しています。 すべての投稿を表示

2022年4月3日日曜日

PySimpleGUIとplaysoundモジュールを使用して、ボタンが押されたら音楽を再生するプログラムを作成する(poetry版)

PySimpleGUIとplaysoundモジュールを使用して、ボタンが押されたら音楽を再生するプログラムを作成するには、以下の手順を実行します。

作成手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. PySimpleGUIとplaysound用の仮想環境作成
poetryを使用する場合は以下のコマンドで、PySimpleGUIとplaysound用の仮想環境を作成します。
sudo apt-get -y install python3-tk tk-dev libcairo2-dev libgirepository1.0-dev

mkdir -p ~/pysimplegui-playsound

cd ~/pysimplegui-playsound

poetry init -n

poetry add PySimpleGUI

poetry add playsound

poetry add pygobject

poetry shell

3. 以下のサンプルプログラムのようにYes/No選択ポップアップとplaysoundモジュールを使用して、「Yes」ボタンが押されたときに音楽がなるようにプログラムします。

confirm-playsound.py
import PySimpleGUI as sg
import playsound

result = sg.popup_yes_no("音楽を鳴らしても良いですか?", title="再生確認")
print(result)
if result == 'Yes':
  playsound.playsound("/usr/share/sounds/sound-icons/piano-3.wav")

・実行コマンド
python confirm-playsound.py

〇サンプルプログラムのスクリーンショット

〇動作確認環境
Ubuntu 20.04

関連情報 ・PySimpleGUIに関する他の記事はこちらを参照してください。

2022年3月19日土曜日

Python WebDAV Client 3を使用してNextcloud上のファイルを削除する(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ファイルを削除する事が出来ます。

インストール手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順 WebDAVクライアントを使用してWebDAV上のファイルを削除します。以下のサンプルプログラムを保存して、実行します。
wdc3_clean.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツの削除
remotepath='Photos/Frog2.jpg'
client.clean(remotepath)

・実行コマンド
python3 wdc3_clean.py

関連情報 ・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月18日金曜日

Python WebDAV Client 3を使用してNextcloud上に指定ディレクトリ上のファイルをアップロードする(poetry版)

Python WebDAV Client 3でNextcloudに接続して、指定ディレクトリ上のファイルをアップロードする事が出来ます。

インストール手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順 WebDAVクライアントを使用してWebDAV上に指定ディレクトリ上のファイルをアップロードします。以下のサンプルプログラムを保存して、実行します。
※アップロード先にあるコンテンツは削除されます
wdc3_upload_directory.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツのアップロード
remotepath='サンプル'
localpath='/tmp/Photos' # あらかじめアップロードするファイルなどは準備してください
client.upload_directory(remotepath, localpath)

・実行コマンド
python3 wdc3_upload_directory.py

関連情報 ・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月17日木曜日

Python WebDAV Client 3を使用してNextcloud上の指定ディレクトリ配下のファイルをダウンロードする(poetry版)

Python WebDAV Client 3でNextcloudに接続して、指定ディレクトリ配下のファイルをダウンロードする事が出来ます。

インストール手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順 WebDAVクライアントを使用してWebDAV上の指定ディレクトリ配下のファイルをダウンロードします。以下のサンプルプログラムを保存して、実行します。
wdc3_download_directory.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツのダウンロード
remotepath='Photos'
localpath='/tmp/Photos'
client.download_directory(remotepath, localpath)

・実行コマンド
python3 wdc3_download_directory.py

関連情報 ・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月16日水曜日

Python WebDAV Client 3を使用してNextcloud上のファイルをコピーする(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ファイルをコピーする事が出来ます。

インストール手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順 WebDAVクライアントを使用してWebDAV上のファイルをコピーします。以下のサンプルプログラムを保存して、実行します。
wdc3_copy.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツのコピー
remotepath_from='Photos/Frog.jpg'
remotepath_to='Photos/Frog2.jpg'
client.copy(remotepath_from, remotepath_to)

・実行コマンド
python3 wdc3_copy.py

関連情報 ・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月15日火曜日

Python WebDAV Client 3を使用してNextcloud上のファイルをダウンロードする(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ファイルをダウンロードする事が出来ます。

インストール手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順 WebDAVクライアントを使用してWebDAV上のファイルをダウンロードします。以下のサンプルプログラムを保存して、実行します。
wdc3_download.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツのダウンロード
remotepath='Nextcloud.png'
localpath='/tmp/Nextcloud.png'
client.download(remotepath, localpath)

・実行コマンド
python3 wdc3_download.py

関連情報 ・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月14日月曜日

Pythonを使用して、Nextcloudのインストール済みアプリ一覧を取得する

Pythonを使用して、Nextcloudのインストール済みアプリ一覧を取得するには、以下の手順を実行します

実行手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、インストールしたアプリ一覧を表示します
nc_list_apps.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'


baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/apps"

headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}

response = requests.get(
  baseuri,
  headers=headers)
print(response.content)

root = etree.fromstring(response.content.decode("utf-8").replace('element>','elem>'))
for record in root.findall('.//elem', root.nsmap):
  print(record.text)

・実行コマンド
python3 nc_list_apps.py

関連情報 ・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

Python WebDAV Client 3を使用してNextcloud上にディレクトリを作成する(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ディレクトリを作成する事が出来ます。

インストール手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順 WebDAVクライアントを使用してWebDAV上にディレクトリを作成します。以下のサンプルプログラムを保存して、実行します。
wdc3_mkdir.py
from webdav3.client import Client

dav_user='test'
dav_password='testpassword'
dav_server='mynextcloud'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# ディレクトリの作成
result = client.mkdir("サンプル")
print(result)
result = client.mkdir("サンプル/音楽")
print(result)

・実行コマンド
python3 wdc3_mkdir.py

関連情報 ・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月13日日曜日

Pythonを使用して、Nextcloudのグループを削除する

Pythonを使用して、Nextcloudのグループを削除するには、以下の手順を実行します

実行手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定グループを削除します
nc_delete_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# 削除するグループ
userid = 'テストグループ'
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/groups/" + userid
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
response = requests.delete(
  baseuri,
  headers=headers)
print(response.content)

・実行コマンド
python3 nc_delete_group.py

関連情報 ・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

Python WebDAV Client 3を使用してNextcloudのファイルを列挙する(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ファイルを列挙する事が出来ます。

インストール手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順 WebDAVクライアントを使用してWebDAVディレクトリの内容を列挙します。以下のサンプルプログラムを保存して、実行します。
wdc3_list.py
from webdav3.client import Client

dav_user='testuser'
dav_password='testpassword'
dav_server='mynextcloud:8080'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

files = client.list(get_info=True)
for file in files:
        if file['isdir'] == True:
                print("directory:" + file['path'])
        else:
                print("file:" + file['path'])

・実行コマンド
python3 wdc3_list.py

関連情報 ・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月12日土曜日

Pythonを使用して、Nextcloudのグループのsubadminを取得する

Pythonを使用して、Nextcloudのグループのsubadminを取得するには、以下の手順を実行します

実行手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定グループのsubadminを返します
nc_subadmins_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# メンバーを取得したいグループ
groupid="サンプルグループ"
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/groups/" + groupid + "/subadmins"
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
response = requests.get(
  baseuri,
  headers=headers)
print(response.content)

root = etree.fromstring(response.content.decode("utf-8").replace('element>','elem>'))
for record in root.findall('.//elem', root.nsmap):
  print(record.text)

・実行コマンド
python3 nc_subadmins_group.py

関連情報 ・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

Python WebDAV Client 3を使用してNextcloud上のファイルの情報を取得する(poetry版)

Python WebDAV Client 3でNextcloudに接続して、ファイルの情報を取得する事が出来ます。

インストール手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="/home/ubuntu/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. webdav-client-python-3のインストール
以下のコマンドでwebdav-client-python-3をインストールした仮想環境を作成します
mkdir -p ~/webdav-client-python-3

cd ~/webdav-client-python-3

poetry init -n

poetry add webdavclient3

poetry shell

実行手順 WebDAVクライアントのinfoメソッドを使用してWebDAV上のファイルの情報を取得します。以下のサンプルプログラムを保存して、実行します。
wdc3_info.py
from webdav3.client import Client

dav_user='testuser'
dav_password='testpassword'
dav_server='yourserver:8080'
options = {
# rootにインストールしていない場合
#'webdav_hostname': "http://" + dav_server + "/nextcloud/remote.php/dav/files/" + dav_user + "/",
# rootにインストールしてある場合
'webdav_hostname': "http://" + dav_server + "/remote.php/dav/files/" + dav_user + "/",
'webdav_login':    dav_user,
'webdav_password': dav_password
}
client = Client(options)
client.verify = False # To not check SSL certificates (Default = True)

# コンテンツの情報を取得
remotepath='Photos/Library.jpg'
result = client.info(remotepath)
for key,value in result.items():
  print("{}={}".format(key, value))

・実行コマンド
python3 wdc3_info.py

関連情報 ・Python WebDAV Client 3
https://github.com/ezhov-evgeny/webdav-client-python-3

・Nextcloudに関するほかの記事は以下のまとめページを参照してください。
Nextcloudのまとめ

2022年3月11日金曜日

Pythonを使用して、Nextcloudのグループメンバーを取得する

Pythonを使用して、Nextcloudのグループメンバーを取得するには、以下の手順を実行します

実行手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定グループのメンバーを返します
nc_members_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# メンバーを取得したいグループ
groupid="サンプルグループ"
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/groups/" + groupid
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
response = requests.get(
  baseuri,
  headers=headers)
print(response.content)

root = etree.fromstring(response.content.decode("utf-8").replace('element>','elem>'))
for record in root.findall('.//elem', root.nsmap):
  print(record.text)

・実行コマンド
python3 nc_members_group.py

関連情報 ・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月10日木曜日

Pythonを使用して、Nextcloudのグループを作成する

Pythonを使用して、Nextcloudのグループを作成するには、以下の手順を実行します

実行手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、グループを作成します。
nc_create_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/groups"
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
# 作成するグループIDを指定します
params  = {'groupid': 'テストグループ'}
response = requests.post(
  baseuri,
  params=params,
  headers=headers)
print(response.content)

・実行コマンド
python3 nc_create_group.py

関連情報 ・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月9日水曜日

PySimpleGUIをインストールして、簡単なウインドウを表示する(poetry版)

PySimpleGUIでGUIを簡単に作成する事が出来ます。

インストール方法 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2. PySimpleGUI用の仮想環境作成
poetryを使用する場合は以下のコマンドで、PySimpleGUI用の仮想環境を作成します。
sudo apt-get -y install python3-tk tk-dev

mkdir -p ~/pysimpleguiproject

cd ~/pysimpleguiproject

poetry init -n

poetry add PySimpleGUI

poetry shell

サンプル実行手順 以下のファイルを保存して、実行します。
sample1.py
import PySimpleGUI as sg

sg.theme('SystemDefault')
layout = [[sg.Text('サンプルです')]]

window = sg.Window('サンプル', layout)
# イベントループ
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED:
        break

window.close()

・実行コマンド
python sample1.py

〇実行結果
以下の小さなウインドウが表示されます。

関連情報 ・pipenvで仮想環境を作成したい場合は、以下のページを参照してください。
PySimpleGUIをインストールして、簡単なウインドウを表示する(pipenv版)

・PySimpleGUIに関する他の記事はこちらを参照してください。

Pythonを使用して、Nextcloudのグループを検索する

Pythonを使用して、Nextcloudのグループを検索するには、以下の手順を実行します

実行手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定文字列を含むグループを返します(パラメータをなしにすると全グループ)。
nc_search_groups.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/groups"
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
#params  = {} # 全グループの場合
params  = {'search': 'サンプル'}
response = requests.get(
  baseuri,
  params=params,
  headers=headers)
#print(response.content)

root = etree.fromstring(response.content.decode("utf-8").replace('element>','elem>'))
for record in root.findall('.//elem', root.nsmap):
  print(record.text)

・実行コマンド
python3 nc_search_groups.py

関連情報 ・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月8日火曜日

Pythonを使用して、Nextcloudの指定ユーザをsubadminから降格する

Pythonを使用して、Nextcloudの指定ユーザをsubadminから降格するには、以下の手順を実行します

実行手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定したユーザをsubadminから降格します。
nc_denote_subadmin.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# subadminから降格するユーザのID
userid = 'sampleuser'
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/users/{}/subadmins".format(userid)
print("baseuri: " + baseuri)
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
params = {
  'groupid': 'サンプルグループ' # subadmin降格対象のグループ
}
response = requests.delete(
  baseuri,
  params=params,
  headers=headers)

print(response.content)

・実行コマンド
python3 nc_denote_subadmin.py

関連情報 ・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月7日月曜日

Pythonを使用して、Nextcloudの指定ユーザをsubadminにする

Pythonを使用して、Nextcloudの指定ユーザをsubadminにするには、以下の手順を実行します

実行手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定したユーザをsubadminに昇格します。
nc_promote_subadmin.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# subadminに昇格するユーザのID
userid = 'sampleuser'
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/users/{}/subadmins".format(userid)
print("baseuri: " + baseuri)
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
params = {
  'groupid': 'サンプルグループ' # subadmin昇格対象のグループ
}
response = requests.post(
  baseuri,
  params=params,
  headers=headers)

print(response.content)

・実行コマンド
python3 nc_promote_subadmin.py

関連情報 ・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月6日日曜日

Pythonを使用して、Nextcloudのユーザの所属グループを削除する

Pythonを使用して、Nextcloudのユーザの所属グループを削除するには、以下の手順を実行します

実行手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定したユーザの所属グループを削除します。
nc_user_remove_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# 所属グループを削除するユーザのID
userid = 'sampleuser'
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/users/{}/groups".format(userid)
print("baseuri: " + baseuri)
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
params = {
  'groupid': 'サンプルグループ' # 削除する所属グループ
}
response = requests.delete(
  baseuri,
  params=params,
  headers=headers)

print(response.content)

・実行コマンド
python3 nc_user_remove_group.py

関連情報 ・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

2022年3月5日土曜日

Pythonを使用して、Nextcloudのユーザの所属グループを追加する

Pythonを使用して、Nextcloudのユーザの所属グループを追加するには、以下の手順を実行します

実行手順 1.poetryのインストール
sudo apt-get update && sudo apt-get -y install python3 python3.8-venv

curl -sSL https://install.python-poetry.org | python3 -

echo 'export PATH="~/.local/bin:$PATH"' >> ~/.profile

source ~/.profile

2.lxmlとrequestsのインストール
以下のコマンドでlxml, requestsをインストールした仮想環境を作成します
mkdir -p ~/nextcloud_api

cd ~/nextcloud_api

poetry init -n

poetry add lxml

poetry add requests

poetry shell

3. プログラムの作成と実行
以下のPythonスクリプトを実行すると、指定したユーザの所属グループを追加します
nc_add_group.py
# coding: utf-8
from lxml import etree
import requests

user = 'adminuser'
password = 'adminpass'
host = 'yourhost:8080'

# 所属グループを追加するユーザのID
userid = 'sampleuser'
baseuri="http://" + user + ":" + password + "@" + host + "/ocs/v1.php/cloud/users/{}/groups".format(userid)
print("baseuri: " + baseuri)
headers = {'content-type': 'application/x-www-form-urlencoded', 'OCS-APIRequest':'true'}
params = {
  'groupid': 'サンプルグループ' # 追加グループ
}
response = requests.post(
  baseuri,
  params=params,
  headers=headers)

print(response.content)

・実行コマンド
python3 nc_add_group.py

関連情報 ・User provisioning API
https://docs.nextcloud.com/server/latest/admin_manual/configuration_user/user_provisioning_api.html

・Nextcloudに関する記事は、以下のまとめを参照してください。
Nextcloudのまとめ

Лучший частный хостинг