Prebuild release 1.0 #2
@@ -52,6 +52,8 @@ jobs:
|
||||
run: |
|
||||
pip install pytest==8.3.4 pytest-asyncio==0.25.3 httpx==0.28.1
|
||||
pip install -r requirements.txt
|
||||
|
||||
- name: Setup moderated base cards
|
||||
working-directory: ./app/tools
|
||||
run: python3 _add_base_cards.py -a 2 -f data/base_cards.json
|
||||
- name: Run pytest
|
||||
run: pytest -vs
|
||||
@@ -0,0 +1,73 @@
|
||||
import argparse
|
||||
import sys
|
||||
import json
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.append('..')
|
||||
from mongo_worker import MongoWorker
|
||||
from schemas.base_schemas import Card
|
||||
|
||||
|
||||
def create_cards(num_cards=10, author_id=1):
|
||||
cards_list = []
|
||||
for card_id in range(1, num_cards + 1):
|
||||
print(f"Creating Card {card_id}")
|
||||
card = Card(
|
||||
card_id=card_id,
|
||||
choice_A=input("Choice A: "),
|
||||
choice_B=input("Choice B: "),
|
||||
author_id=author_id,
|
||||
creation_date=datetime.now().isoformat(),
|
||||
moderation_date=datetime.now().isoformat(),
|
||||
active_status=True
|
||||
)
|
||||
cards_list.append(card)
|
||||
return cards_list
|
||||
|
||||
def read_json(json_file):
|
||||
try:
|
||||
with open(json_file, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
return [Card(**card) for card in data]
|
||||
except Exception as e:
|
||||
print(f"Error reading JSON file: {e}")
|
||||
return []
|
||||
|
||||
def write_json(cards_list, json_file):
|
||||
try:
|
||||
with open(json_file, 'w', encoding='utf-8') as f:
|
||||
json.dump([card.model_dump() for card in cards_list], f, ensure_ascii=False, indent=4)
|
||||
print(f"Successfully saved {len(cards_list)} cards to {json_file}")
|
||||
except Exception as e:
|
||||
print(f"Error writing to JSON file: {e}")
|
||||
|
||||
def add_cards_to_mongodb(cards_list):
|
||||
mongo = MongoWorker()
|
||||
for card in cards_list:
|
||||
mongo.add_card_by_base_model(card)
|
||||
print(f"Successfully added {len(cards_list)} cards to MongoDB")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-a', '--action', type=int, required=True, choices=[0, 1, 2],
|
||||
help="0 - Manual input & save to MongoDB, 1 - Manual input & save to JSON, 2 - Read JSON & save to MongoDB")
|
||||
parser.add_argument('-f', '--file', type=str, default="cards.json", help="JSON file name for reading/writing")
|
||||
parser.add_argument('-n', '--num', type=int, default=10, help="Number of cards to create")
|
||||
parser.add_argument('-u', '--user', type=int, default=1, help="Author ID")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.action == 0:
|
||||
cards = create_cards(args.num, args.user)
|
||||
add_cards_to_mongodb(cards)
|
||||
elif args.action == 1:
|
||||
cards = create_cards(args.num, args.user)
|
||||
write_json(cards, args.file)
|
||||
elif args.action == 2:
|
||||
cards = read_json(args.file)
|
||||
if cards:
|
||||
add_cards_to_mongodb(cards)
|
||||
else:
|
||||
print("No valid cards found in JSON file.")
|
||||
@@ -0,0 +1,152 @@
|
||||
[
|
||||
{
|
||||
"card_id": 1,
|
||||
"choice_A": "Котики",
|
||||
"choice_B": "Собачки",
|
||||
"count_choice_A": 0,
|
||||
"count_choice_B": 0,
|
||||
"count_total": 0,
|
||||
"count_likes": 0,
|
||||
"count_dislikes": 0,
|
||||
"comments": [],
|
||||
"author_id": 1,
|
||||
"creation_date": "2025-03-04T16:56:05.290110",
|
||||
"moderation_date": "2025-03-04T16:56:05.290143",
|
||||
"active_status": true
|
||||
},
|
||||
{
|
||||
"card_id": 2,
|
||||
"choice_A": "Чай",
|
||||
"choice_B": "Кофе",
|
||||
"count_choice_A": 0,
|
||||
"count_choice_B": 0,
|
||||
"count_total": 0,
|
||||
"count_likes": 0,
|
||||
"count_dislikes": 0,
|
||||
"comments": [],
|
||||
"author_id": 1,
|
||||
"creation_date": "2025-03-04T16:56:11.108762",
|
||||
"moderation_date": "2025-03-04T16:56:11.108793",
|
||||
"active_status": true
|
||||
},
|
||||
{
|
||||
"card_id": 3,
|
||||
"choice_A": "Поездка в горы",
|
||||
"choice_B": "Поездка на море",
|
||||
"count_choice_A": 0,
|
||||
"count_choice_B": 0,
|
||||
"count_total": 0,
|
||||
"count_likes": 0,
|
||||
"count_dislikes": 0,
|
||||
"comments": [],
|
||||
"author_id": 1,
|
||||
"creation_date": "2025-03-04T16:56:25.062542",
|
||||
"moderation_date": "2025-03-04T16:56:25.062586",
|
||||
"active_status": true
|
||||
},
|
||||
{
|
||||
"card_id": 4,
|
||||
"choice_A": "День",
|
||||
"choice_B": "Ночь",
|
||||
"count_choice_A": 0,
|
||||
"count_choice_B": 0,
|
||||
"count_total": 0,
|
||||
"count_likes": 0,
|
||||
"count_dislikes": 0,
|
||||
"comments": [],
|
||||
"author_id": 1,
|
||||
"creation_date": "2025-03-04T16:56:34.148692",
|
||||
"moderation_date": "2025-03-04T16:56:34.148725",
|
||||
"active_status": true
|
||||
},
|
||||
{
|
||||
"card_id": 5,
|
||||
"choice_A": "Работать в офисе",
|
||||
"choice_B": "Работать удалённо",
|
||||
"count_choice_A": 0,
|
||||
"count_choice_B": 0,
|
||||
"count_total": 0,
|
||||
"count_likes": 0,
|
||||
"count_dislikes": 0,
|
||||
"comments": [],
|
||||
"author_id": 1,
|
||||
"creation_date": "2025-03-04T16:57:00.723472",
|
||||
"moderation_date": "2025-03-04T16:57:00.723518",
|
||||
"active_status": true
|
||||
},
|
||||
{
|
||||
"card_id": 6,
|
||||
"choice_A": "Заниматься спортом",
|
||||
"choice_B": "Играть в видеоигры",
|
||||
"count_choice_A": 0,
|
||||
"count_choice_B": 0,
|
||||
"count_total": 0,
|
||||
"count_likes": 0,
|
||||
"count_dislikes": 0,
|
||||
"comments": [],
|
||||
"author_id": 1,
|
||||
"creation_date": "2025-03-04T16:57:31.524721",
|
||||
"moderation_date": "2025-03-04T16:57:31.524754",
|
||||
"active_status": true
|
||||
},
|
||||
{
|
||||
"card_id": 7,
|
||||
"choice_A": "Гулять",
|
||||
"choice_B": "Сидеть дома",
|
||||
"count_choice_A": 0,
|
||||
"count_choice_B": 0,
|
||||
"count_total": 0,
|
||||
"count_likes": 0,
|
||||
"count_dislikes": 0,
|
||||
"comments": [],
|
||||
"author_id": 1,
|
||||
"creation_date": "2025-03-04T16:57:52.022380",
|
||||
"moderation_date": "2025-03-04T16:57:52.022413",
|
||||
"active_status": true
|
||||
},
|
||||
{
|
||||
"card_id": 8,
|
||||
"choice_A": "Посмотреть фильм",
|
||||
"choice_B": "Почитать книжку",
|
||||
"count_choice_A": 0,
|
||||
"count_choice_B": 0,
|
||||
"count_total": 0,
|
||||
"count_likes": 0,
|
||||
"count_dislikes": 0,
|
||||
"comments": [],
|
||||
"author_id": 1,
|
||||
"creation_date": "2025-03-04T16:58:15.032749",
|
||||
"moderation_date": "2025-03-04T16:58:15.032762",
|
||||
"active_status": true
|
||||
},
|
||||
{
|
||||
"card_id": 9,
|
||||
"choice_A": "Зима",
|
||||
"choice_B": "Лето",
|
||||
"count_choice_A": 0,
|
||||
"count_choice_B": 0,
|
||||
"count_total": 0,
|
||||
"count_likes": 0,
|
||||
"count_dislikes": 0,
|
||||
"comments": [],
|
||||
"author_id": 1,
|
||||
"creation_date": "2025-03-04T16:58:24.800416",
|
||||
"moderation_date": "2025-03-04T16:58:24.800450",
|
||||
"active_status": true
|
||||
},
|
||||
{
|
||||
"card_id": 10,
|
||||
"choice_A": "Лучший друг/подруга",
|
||||
"choice_B": "Любимый человек",
|
||||
"count_choice_A": 0,
|
||||
"count_choice_B": 0,
|
||||
"count_total": 0,
|
||||
"count_likes": 0,
|
||||
"count_dislikes": 0,
|
||||
"comments": [],
|
||||
"author_id": 1,
|
||||
"creation_date": "2025-03-04T16:59:05.265795",
|
||||
"moderation_date": "2025-03-04T16:59:05.265829",
|
||||
"active_status": true
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user