Skip to content

Commit

Permalink
feat: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamhunter2333 committed Jul 10, 2024
1 parent 01b47e0 commit ebbaf0c
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 69 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/main.yml

This file was deleted.

39 changes: 22 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,35 @@ name: Docker Image Release
on:
push:
tags:
- '*.*.*'
- "*.*.*"

jobs:
env:
REGISTRY: ghcr.io

jobs:
build:

runs-on: ubuntu-latest
steps:
- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}

- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Docker Login
uses: docker/login-action@v1.8.0
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: dreamhunter2333.azurecr.io
username: ${{ secrets.AZURE_REGISTRY_USERNAME }}
password: ${{ secrets.AZURE_REGISTRY_PASSWORD }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build the Docker image
run: docker build . --file docker/dockerfile --tag dreamhunter2333.azurecr.io/awsl/awsl:${{ steps.get_version.outputs.VERSION }}
- name: Push the Docker image
run: docker push dreamhunter2333.azurecr.io/awsl/awsl:${{ steps.get_version.outputs.VERSION }}
- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
file: docker/dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ github.repository }}:${{ github.ref_name }}
${{ env.REGISTRY }}/${{ github.repository }}:latest
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ __pycache__/
venv/
.env.local
.env.*.local
celerybeat-schedule
11 changes: 10 additions & 1 deletion readme.md → README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# weibo 爬虫

本爬虫仅供学习交流,请不要非法使用(后果自负
> 本爬虫仅供学习交流,请不要非法使用(后果自负
自动爬取某个微博博主转发的微博,根据关键词匹配,记录匹配到的微博的图片

Expand All @@ -13,3 +13,12 @@ db_url=mysql+mysqlconnector://xxx:xxx/xxx(数据库地址)
pika_url=xxx://:xxx@localhost:6379/0(MQ)
bot_queue=xxx(MQ)
```

运行

```bash
python3 -m venv venv
source venv/bin/activate
python3 -m pip install -r requirements.txt
python3 main.py
```
14 changes: 7 additions & 7 deletions awsl/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from pydantic import BaseSettings
from pydantic_settings import BaseSettings


WB_DATA_URL = "https://weibo.com/ajax/statuses/mymblog?uid={}&page="
Expand All @@ -13,12 +13,12 @@


class Settings(BaseSettings):
cookie_sub: str
max_page: int
max_workers: int
db_url: str
pika_url: str
bot_queue: str
cookie_sub: str = ""
max_page: int = ""
max_workers: int = 5
db_url: str = ""
pika_url: str = ""
bot_queue: str = ""

class Config:
env_file = os.environ.get("ENV_FILE", ".env")
Expand Down
8 changes: 6 additions & 2 deletions awsl/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
channel = None


def get_channel() -> None:
def check_pika_channel() -> None:
global channel
if not settings.pika_url or not settings.bot_queue:
return
if channel is not None and channel.is_open:
return
connection = pika.BlockingConnection(pika.URLParameters(settings.pika_url))
Expand Down Expand Up @@ -129,7 +131,9 @@ def find_all_awsl_producer() -> List[AwslProducer]:
@staticmethod
def send2bot(awsl_producer: AwslProducer, re_mblogid: str, re_wbdata: dict) -> None:
try:
get_channel()
check_pika_channel()
if not channel:
return
wb_url = WB_URL_PREFIX.format(
re_wbdata["user"]["id"], re_wbdata["mblogid"])
pic_infos = re_wbdata.get("pic_infos", {})
Expand Down
10 changes: 4 additions & 6 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
version: "2"

services:

awsl-task:
image: registry.cn-beijing.aliyuncs.com/dreamhunter/awsl:2.0
build:
context: ..
dockerfile: docker/dockerfile
image: awsl-task
container_name: awsl-task
restart: always
environment:
ENV_FILE: .env
volumes:
- ../.env.local:.env
5 changes: 3 additions & 2 deletions docker/dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM python:3.9-slim
FROM python:3.12-slim

COPY . /app
WORKDIR /app
RUN python3 -m pip install -r /app/requirements.txt
RUN rm -rf /root/.cache
ENTRYPOINT ["python3", "start.py"]

ENTRYPOINT ["python3", "main.py"]
File renamed without changes.
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mysql-connector-python==8.0.27
pika==1.2.0
pydantic==1.8.2
python-dotenv==0.19.0
requests==2.26.0
SQLAlchemy==1.4.27
mysql-connector-python==9.0.0
pika==1.3.2
pydantic==2.8.2
pydantic-settings==2.3.4
requests==2.32.3
SQLAlchemy==2.0.31

0 comments on commit ebbaf0c

Please sign in to comment.