116 lines
4.1 KiB
Python
116 lines
4.1 KiB
Python
import requests
|
|
import json
|
|
from googletrans import Translator
|
|
import firebase_admin
|
|
from firebase_admin import credentials, firestore
|
|
|
|
def initialize_firebase():
|
|
# Ścieżka do pliku JSON z kluczem usługi
|
|
cred = credentials.Certificate('./dexterlab.json')
|
|
|
|
# Inicjalizacja aplikacji Firebase
|
|
firebase_admin.initialize_app(cred)
|
|
|
|
# Inicjalizacja klienta Firestore
|
|
return firestore.client()
|
|
|
|
def save_data(db, data, company):
|
|
try:
|
|
# Przykład zapisu danych do kolekcji 'users'
|
|
doc_ref = db.collection('plugins').document(company)
|
|
doc_ref.set(data)
|
|
print("Dane zostały zapisane")
|
|
|
|
except Exception as e:
|
|
print(f"Wystąpił błąd podczas zapisywania danych: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
def translate_text(text, target_language='pl'):
|
|
translator = Translator()
|
|
translation = translator.translate(text, dest=target_language)
|
|
return translation.text
|
|
|
|
def get_popular_plugins():
|
|
# Endpoint API WordPress.org
|
|
url = "https://api.wordpress.org/plugins/info/1.2/"
|
|
|
|
# Parametry zapytania
|
|
params = {
|
|
"action": "query_plugins",
|
|
"request[browse]": "popular",
|
|
"request[per_page]": 50 # Możesz zmienić na inną liczbę
|
|
}
|
|
|
|
# Wysłanie zapytania GET do API
|
|
response = requests.get(url, params=params)
|
|
|
|
# Sprawdzenie odpowiedzi
|
|
if response.status_code == 200:
|
|
response_json = response.json()
|
|
return response_json.get('plugins', [])
|
|
else:
|
|
print(f"Błąd: {response.status_code}")
|
|
return []
|
|
|
|
|
|
def transform_plugin_data(plugin_data):
|
|
# Przetłumaczenie short_description na język polski
|
|
translated_description = translate_text(plugin_data.get('short_description'))
|
|
|
|
# Przekształcenie danych na bardziej "ludzką" postać
|
|
transformed_data = {
|
|
"Nazwa": plugin_data.get('name'),
|
|
"Wersja": plugin_data.get('version'),
|
|
"Autor": {
|
|
"Nazwa": plugin_data.get('author').split('">')[1].split('</a>')[0],
|
|
"Strona_autora": plugin_data.get('author').split('"')[1],
|
|
"Profil_autora": plugin_data.get('author_profile')
|
|
},
|
|
"Wymagania": {
|
|
"WordPress": plugin_data.get('requires'),
|
|
"PHP": plugin_data.get('requires_php'),
|
|
"Przetestowane_na": plugin_data.get('tested'),
|
|
"Wymagane_wtyczki": plugin_data.get('requires_plugins', [])
|
|
},
|
|
"Oceny": {
|
|
"Średnia_ocena": plugin_data.get('rating'),
|
|
"Liczba_ocen": plugin_data.get('num_ratings'),
|
|
"Szczegóły_ocen": {
|
|
"5_gwiazdki": plugin_data['ratings'].get('5'),
|
|
"4_gwiazdki": plugin_data['ratings'].get('4'),
|
|
"3_gwiazdki": plugin_data['ratings'].get('3'),
|
|
"2_gwiazdki": plugin_data['ratings'].get('2'),
|
|
"1_gwiazdka": plugin_data['ratings'].get('1')
|
|
}
|
|
},
|
|
"Wsparcie": {
|
|
"Liczba_wątków": plugin_data.get('support_threads'),
|
|
"Rozwiązane_wątki": plugin_data.get('support_threads_resolved')
|
|
},
|
|
"Instalacje": {
|
|
"Aktywne_instalacje": plugin_data.get('active_installs'),
|
|
"Liczba_pobrań": plugin_data.get('downloaded')
|
|
},
|
|
"Ostatnia_aktualizacja": plugin_data.get('last_updated'),
|
|
"Data_dodania": plugin_data.get('added'),
|
|
"Strona_domowa": plugin_data.get('homepage'),
|
|
"Link_do_pobrania": plugin_data.get('download_link'),
|
|
"Opis": translated_description, # Użycie przetłumaczonego opisu
|
|
"Szczegółowy_opis": plugin_data.get('description'),
|
|
"Tagi": list(plugin_data.get('tags').values()),
|
|
"Ikony": {
|
|
"1x": plugin_data['icons'].get('1x'),
|
|
"2x": plugin_data['icons'].get('2x')
|
|
}
|
|
}
|
|
save_data(db, transformed_data,plugin_data.get('name') )
|
|
return transformed_data
|
|
|
|
if __name__ == "__main__":
|
|
db = initialize_firebase()
|
|
plugins = get_popular_plugins()
|
|
human_readable_plugins = [transform_plugin_data(plugin) for plugin in plugins]
|
|
#print(json.dumps(human_readable_plugins, indent=4, ensure_ascii=False)) |