Chrony时间服务配置及查询

1
2
3
systemctl status chronyd
# 查看时间同步源
chronyc sources -v

参考资料

https://blog.csdn.net/whale0306/article/details/128828944

配置ChatGPT4分享系统

go-chatgpt-api

https://github.com/linweiyuan/go-chatgpt-api

使用docker部署,该项目为第三方API,通过逆向openai网页得到,基本和网页端F12获得接口一致,但没有限制

1
2
3
4
5
6
7
8
9
10
services:
go-chatgpt-api:
container_name: go-chatgpt-api
image: linweiyuan/go-chatgpt-api
ports:
- 8080:8080
environment:
- GIN_MODE=release
- GO_CHATGPT_API_PROXY=http://127.0.0.1:1081
restart: unless-stopped
阅读全文 »

Python3.10安装uWSGI解决libpython3.10.a不存在

方法一:编译安装

1
2
3
4
5
6
7
8
wget -t 100 -c https://www.python.org/ftp/python/3.10.4/Python-3.10.4.tgz
tar -zxf Python-3.10.4.tgz
cd Python-3.10.4/
./configure --prefix=/tmp/Python
make -j4
make install
# 复制到目标路径
cp /tmp/Python/lib/libpython3.9.a ~/softwares/anaconda3/lib/python3.9/config-3.9-x86_64-linux-gnu/

方法二:conda

conda install -c conda-forge uwsgi

阅读全文 »

解决宝塔面板docker容器内没网的问题

1
2
3
4
5
6
7
kill docker

iptables -t nat -F

ifconfig docker0 down

systemctl restart docker.service

原理重启网络,建立映射关系

参考

https://blog.csdn.net/yuanzelin8/article/details/126158989

阅读全文 »

CloudFlare-Warp

官网

http://1.1.1.1

使用

1
2
sudo rpm -ivh https://pkg.cloudflareclient.com/cloudflare-release-el8.rpm
sudo dnf install cloudflare-warp
阅读全文 »

用uWSGI托管django项目

  1. 安装pip install uwsgi
  2. 添加软连接ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi
  3. vim uwsgi.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# uwsig使用配置文件启动
[uwsgi]
# 项目目录
chdir=/workspace/django_project/dp_api/dataplatform/
# 指定项目的application
module=dataplatform.wsgi:application
# 指定sock的文件路径
socket=/workspace/django_project/dp_api/script/uwsgi.sock
# 进程个数
workers=5
pidfile=/workspace/django_project/dp_api/script/uwsgi.pid
# 指定IP端口
http=10.226.128.185:8001
# 指定静态文件
# static-map=/static=/workspace/django_project/dp_api/dataplatform/static
# 启动uwsgi的用户名和用户组
uid=root
gid=root
# 启用主进程
master=true
# 自动移除unix Socket和pid文件当服务停止的时候
vacuum=true
# 序列化接受的内容,如果可能的话
thunder-lock=true
# 启用线程
enable-threads=true
# 设置自中断时间
harakiri=30
# 设置缓冲
post-buffering=4096
# 设置日志目录
daemonize=/workspace/django_project/dp_api/script/uwsgi.log
  1. 启动uwsgi --ini uwsgi.ini
  2. 停止uwsgi --stop uwsgi.pid

参考资料

阅读全文 »

高德地理信息转换和天气API

https://lbs.amap.com/api/webservice/guide/api/georegeo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
    url = r'https://restapi.amap.com/v3/geocode/regeo'
params = {
'key': settings.GD_KEY,
'location': str(longitude) + ',' + str(latitude),
'radius': 100,
'output': 'json'
}
response = requests.get(url=url, params=params)
print(response.json())
province = response.json()['regeocode']['addressComponent']['province']
district = response.json()['regeocode']['addressComponent']['district']
city = response.json()['regeocode']['addressComponent']['city']
location = response.json()['regeocode']['formatted_address']
# 高德地区编码,可用于查询天气等信息
adcode = response.json()['regeocode']['addressComponent']['adcode']
return location, province, city, district, adcode


def gd_weather(adcode, extensions: str = 'base') -> dict:
'''
all是返回格式参考:
{'city': '甘德县', 'adcode': '632623', 'province': '青海', 'reporttime': '2023-03-28 12:19:30', 'casts': [{'date': '2023-03-28', 'week': '2', 'dayweather': '小雪', 'nightweather': '小雪', 'daytemp': '2', 'nighttemp': '-9', 'daywind': '东', 'nightwind': '东', 'daypower': '4', 'nightpower': '≤3', 'daytemp_float': '1.5', 'nighttemp_float': '-8.9'}, {'date': '2023-03-29', 'week': '3', 'dayweather': '多云', 'nightweather': '多云', 'daytemp': '4', 'nighttemp': '-10', 'daywind': '西南', 'nightwind': '西', 'daypower': '4', 'nightpower': '≤3', 'daytemp_float': '3.7', 'nighttemp_float': '-9.6'}, {'date': '2023-03-30', 'week': '4', 'dayweather': '多云', 'nightweather': '阴', 'daytemp': '4', 'nighttemp': '-7', 'daywind': '西', 'nightwind':'西', 'daypower': '≤3', 'nightpower': '4', 'daytemp_float': '4.2', 'nighttemp_float': '-7.1'}, {'date': '2023-03-31', 'week': '5', 'dayweather': '阴', 'nightweather': '多云', 'daytemp': '4', 'nighttemp': '-9', 'daywind': '西', 'nightwind': '西南', 'daypower': '5', 'nightpower': '≤3', 'daytemp_float': '4.0', 'nighttemp_float': '-8.7'}]}
base返回样式参考:
{'province': '青海', 'city': '甘德县', 'adcode': '632623', 'weather': '多云', 'temperature': '-7', 'winddirection': '东', 'windpower': '≤3', 'humidity': '82', 'reporttime': '2023-03-28 12:19:30', 'temperature_float': '-7.0', 'humidity_float': '82.0'}
'''
url = r'https://restapi.amap.com/v3/weather/weatherInfo'
params = {
'key': settings.GD_KEY,
'city': adcode,
'extensions': 'base' if extensions == 'base' else 'all',
'output': 'JSON'
}
response = requests.get(url=url, params=params)
print(response.json())
if extensions == 'base':
return response.json()['lives'][0]
else:
return response.json()['forecasts'][0]


def gd_location_adcode(location:str):
url = r'https://restapi.amap.com/v3/geocode/geo'
params = {
'key': settings.GD_KEY,
'address': location,
'output': 'json'
}
response = requests.get(url=url, params=params)
print(response.json())
# 高德地区编码,可用于查询天气等信息
adcode = response.json()['geocodes'][0]['adcode']
return adcode

Nginx反代ChatGPT

1
2
3
4
5
6
7
8
9
location /v1/ {
proxy_pass https://api.openai.com/v1/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 必须开启SNI,否则会404或502
proxy_ssl_server_name on;
proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
}

否则会报错:SSL_do_handshake() failed (SSL: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure) while SSL handshaking to upstream

引用

  1. https://zhuanlan.zhihu.com/p/547260827
  2. https://en.wikipedia.org/wiki/Server_Name_Indication
  3. https://blog.csdn.net/jeccisnd/article/details/99300178
阅读全文 »

Django+wechatpy+ChatGPT+Celery接入微信公众号、企业微信

安装模块

1
2
3
4
# 安装django
pip install django
# 安装WeChatpy
pip install wechatpy

新建项目

1
2
3
4
# 创建一个django项目
django-admin startproject wechat .
# 创建一个应用demo
python3 manage.py startapp demo
阅读全文 »

需要nginx必看,不要托管静态文件目录

https://pywebio.readthedocs.io/zh_CN/latest/misc.html?highlight=nginx#nginx-websocket-config-example

参考

0%