Új hozzászólás Aktív témák
-
Pxs
aktív tag
válasz
Hege1234
#4326
üzenetére
Köszi, működött!
Igen, olyasmi, egy jóval nagyobb script részeként.Most meg van egy ilyen mókám, szintén JSON (illetve Python-dict), ahol egy meglévő "hazai_csapat_lejatszott_meccsek" változóba kellene átadnom a 98. sorban lévő ""name": "Overall Matched Played"" kulcs feletti "value": "1" kulcs értékét (1-et).
De mindezt úgy, hogy még előtte ellenőriznie kellene, hogy a 21. sorban lévő ""name": "FC Bayern München" kulcs értéke megegyezik-e a "hazai_csapat" változó értékével, csak akkor keressen tovább az említett "Overall Matched Played" string-ig, és mielőtt azt megtalálja, mentse egy ideiglenes változóba minden iteráció során az összes "value" kulcsot, amibe útközben akad.
(úgy, hogy aztán felhasználható maradjon későbbre is a legutolsó mentett érték)Bocs, még nagyon kapkodom a fejem e téren, pedig van némi programozási tapasztalatom

{
"data": [
{
"id": 241976,
"participant_id": 503,
"sport_id": 1,
"league_id": 2,
"season_id": 23619,
"stage_id": 77471317,
"group_id": null,
"round_id": 357241,
"standing_rule_id": 117850,
"position": 1,
"result": "equal",
"points": 3,
"participant": {
"id": 503,
"sport_id": 1,
"country_id": 11,
"venue_id": 53,
"name": "FC Bayern München"
},
"details": [
{
"id": 3523848805,
"standing_type": "standing",
"standing_id": 241976,
"type_id": 130,
"value": 1,
"type": {
"id": 130,
"name": "Overall Won"
}
},
{
"id": 3523848806,
"standing_type": "standing",
"standing_id": 241976,
"type_id": 131,
"value": 0,
"type": {
"id": 131,
"name": "Overall Draw"
}
},
{
"id": 3523848802,
"standing_type": "standing",
"standing_id": 241976,
"type_id": 133,
"value": 9,
"type": {
"id": 133,
"name": "Overal Goals Scored"
}
},
{
"id": 3523848819,
"standing_type": "standing",
"standing_id": 241976,
"type_id": 144,
"value": 0,
"type": {
"id": 144,
"name": "Away Lost"
}
},
{
"id": 3523848803,
"standing_type": "standing",
"standing_id": 241976,
"type_id": 134,
"value": 2,
"type": {
"id": 134,
"name": "Overall Goals Conceded"
}
},
{
"id": 3523848815,
"standing_type": "standing",
"standing_id": 241976,
"type_id": 187,
"value": 3,
"type": {
"id": 187,
"name": "Overall Points"
}
},
{
"id": 3523848804,
"standing_type": "standing",
"standing_id": 241976,
"type_id": 129,
"value": 1,
"type": {
"id": 129,
"name": "Overall Matched Played"
} -
Pxs
aktív tag
A keresés pedig az alábbi kóddal fut:
league_id = result['league_id']
standings_url = f"https://api.sportmonks.com/v3/football/standings/live/leagues/{league_id}?include=participant"
standings_response = requests.get(standings_url, headers=headers)
if standings_response.status_code == 200:
try:
standings_data = standings_response.json()
# Alakítsa át a kapott eredményt python-szótárrá
standings = standings_data.get("data", [])
# A team1 és team2 mentése és kiírása
if " vs " in search_value:
team1, team2 = search_value.split(" vs ", 1)
team1 = team1.strip()
team2 = team2.strip()
print(f"TEAM1: {team1}")
print(f"TEAM2: {team2}")
# Keresés a team1 értékére az állás adatokban
print(f"team1 keresett értéke: {team1}")
team1_found = False
for group in standings:
if isinstance(group, dict):
participants = group.get("standings", [])
for team in participants:
participant = team.get("participant", {})
if participant.get("name") == team1:
print("TEAM1 jelen")
print(f"Csapat ID: {participant.get('id')}")
print(f"Pozíció: {team.get('position')}")
print(f"Pontok: {team.get('points')}")
team1_found = True
break
if team1_found:
break
if not team1_found:
print("TEAM1 nincs az állások között.")
else:
print("A meccsnév nem megfelelő formátumú.") -
Pxs
aktív tag
Sziasztok, elég új nekem még a Python, és van egy ilyen adatszerkezetem, amit JSON-ban kapok egy API-endpoint meghívása után.
Foci tabella állások egy adott ligában, és ebből lenne szükségem az adott csapat nevére ("name" kulcs), ID-jára ("id" kulcs, de ebből van egy az eggyel feljebb lévő szinten is, nem az kell, mert az az állás ID-ja), helyezésére ("position" kulcs), és pontszámára ("points" kulcs).
Viszont első körben a csapat nevét kellene megtalálnia, aztán az ahhoz tartozó ID-t, és a szerintem nagyobb probléma, hogy a "position" és a "points" kulcsok már egy szinttel feljebb találhatók.
Miként lehetne ezt megoldani? Már a PyCharm AI-asszisztense is csődött mondott, vagy én használom rosszul.
Illetve fontos Python dictionary-be konvertálni a keresés előtt a JSON-objectet? Előre is köszi!
"data": [
{
"id": 18404871,
"sport_id": 1,
"league_id": 2,
"season_id": 23619,
"stage_id": 77471317,
"group_id": null,
"round_id": 357241,
"participant_id": 503,
"standing_rule_id": 117850,
"position": 1,
"points": 3,
"result": "equal",
"participant": {
"id": 503,
"sport_id": 1,
"country_id": 11,
"venue_id": 53,
"gender": "male",
"name": "FC Bayern München",
"short_code": "FCB",
"image_path": "https://cdn.sportmonks.com/images/soccer/teams/23/503.png",
"founded": 1900,
"type": "domestic",
"placeholder": false,
"last_played_at": "2024-09-21 13:30:00"
}
Új hozzászólás Aktív témák
- Beszámítás! MSI G27C4 E3 27 180Hz FHD VA 1ms gamer monitor garanciával hibátlan működéssel
- Beszámítás! Benq Zowie XL2411 24 144Hz FHD TN 1ms monitor garanciával hibátlan működéssel
- Beszámítás! Asus TUF VG249Q 24 144Hz FHD IPS 1ms monitor garanciával hibátlan működéssel
- Beszámítás! LG UltraGear 27GL850 144Hz QHD IPS 1ms monitor garanciával hibátlan működéssel
- BESZÁMÍTÁS! MSI Cyborg 15 A12VF FHD GAMER notebook - i5 12450H 16GB DDR5 512GB SSD RTX 4060 8GB
- MEDION ERAZER Cooling Kit V2 Vízhűtés - MD 62737 Beast 16 X1 gamer laptophoz
- HIBÁTLAN iPhone 13 Pro 256GB Graphite -1 ÉV GARANCIA - Kártyafüggetlen, MS4648, 100% AKKSI
- ÁRGARANCIA! Épített KomPhone Ultra 9 285K 32/64GB RAM RTX 5070 Ti 16GB GAMER PC termékbeszámítással
- DELL Latitude 5480, 14",HD,i3-7100U,8GB DDR4,256GB SSD,WIN11
- Bomba ár! HP ZBook 17 - i7-4800MQ I 32GB I 256SSD+750GB I Nvidia I 17,3" FHD I Cam I W10 I Gari!
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
(úgy, hogy aztán felhasználható maradjon későbbre is a legutolsó mentett érték)
