Skip to content

Commit ad49e64

Browse files
committed
добавил dotenv, requirements
1 parent 70dd58a commit ad49e64

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

forgejo/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API_TOKEN=62ce13fb948ae0551c0512e14059000ffa35be64

forgejo/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212

1313
Перед началом работы установите необходимые библиотеки:
1414

15-
```pip install pyforgejo```
15+
```pip install -r requirements.txt```
1616

1717
## Настройка API-токена
1818

19-
В файл `token` запишите в файл API-ключ в формате:
19+
Создайте .env файл с токеном pyforgejo в рабочей папке скрипта. Пример находится в папке с клиентом.
2020

21-
`token your_api_key_here`
21+
```
22+
API_TOKEN=62ce13fb948ae0551c0512e14059000ffa35be64
23+
```
2224

2325
## Запуск скрипта
2426

forgejo/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
from dotenv import dotenv_values
12
from pyforgejo import PyforgejoApi
23

3-
with open('token') as file:
4-
API_KEY = file.read()
5-
if not API_KEY:
6-
print("API_KEY not found")
7-
exit(1)
4+
config = dotenv_values(".env")
85

9-
client = PyforgejoApi(base_url="https://codeberg.org/api/v1", api_key=API_KEY)
6+
if not "API_TOKEN" in config:
7+
print("Cannot find API_TOKEN in .env file. Check if it exists and has correct token. Aborting...")
8+
exit(1)
9+
client = PyforgejoApi(base_url="https://codeberg.org/api/v1", api_key=config["API_TOKEN"])
1010

1111
repo = client.repository.repo_get(owner="harabat", repo="pyforgejo")
1212

1313

1414
print(f"Название: {repo.name}")
15-
print(f"Описание: {repo.description}")
15+
print(f"Описание: {repo.description}")

forgejo/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pyforgejo==2.0.0
2+
python-dotenv==1.0.1

0 commit comments

Comments
 (0)