Funktionsamnesie?

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Funktionsamnesie?

30 Mar 2021, 11:20

Code: Select all

cityID		:="Q627742"
fromCityID	:="Q627742"																
toCityID	:="Q4165"
distUnit	:="KM"

; erste Zeile wird aus Variable gepeist, die Zeile darunter is statisch. Beide sollen identisch sein.
	MsgBox	%	"geo/cities/" . cityID . "/distance?fromCityID=" . fromCityID . "&distanceUnit=" . distUnit . "&toCityID=" . toCityID . "`n"
			.	"geo/cities/Q627742/distance?fromCityID=Q627742&distanceUnit=KM&toCityID=Q4165"

; ... obwohl beide identisch sind, wird diese Zeile, wenn statisch in der Funktion übergeben, korrekt vom Zielserver beantwortet, ...
	MsgBox	% geoDB("geo/cities/Q627742/distance?fromCityID=Q627742&distanceUnit=KM&toCityID=Q4165")

; b) bei der Variablen-Variante gibt der Server jedoch einen "fehlender Parameter"-Fehler zurück! Barum??
	MsgBox	% geoDB("geo/cities/" . cityID . "/distance?fromCityID=" . fromCityID . "&distanceUnit=" . distUnit . "&toCityID=" . toCityID)

geoDB(url) {
	myAPIKey := <your API key here>																					
	host:="https://wft-geo-db.p.rapidapi.com/v1/"
	url :=	StrReplace(url,A_Space,"%20")
	req := ComObjCreate("Msxml2.XMLHTTP")
	
	MsgBox % clipboard := host . url
	
	req.open("GET", host . url, False)
	req.setRequestHeader("x-rapidapi-key",myAPIKey)
	req.setRequestHeader("x-rapidapi-host","wft-geo-db.p.rapidapi.com")
	req.setRequestHeader("Content-Type","application/json; charset=utf-8")
	req.setRequestHeader("useQueryString","true")
	req.Send(data)
	Sleep, 1000
	Return req.responseText
	}
... hier scheint die Funktion gaga zu gehn. Es gibt übrigens 25 weitere Funktionalitäten/Anfragen (auch mit variablen Bestandteilen in der URL) die der Server über dieselbe Funktion fehlerfrei beantwortet. Any thoughts?? :think:
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Funktionsamnesie?

31 Mar 2021, 07:07

Moin BoBo,

ich sehe keinen Grund, es sei denn, die Variablen werden vor dem Funktionsaufruf verwurschtelt oder existieren nicht.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Funktionsamnesie?

31 Mar 2021, 14:31

Kann ich nicht bestätigen, die MsgBox unmittelbar vor der Übergabe zeigt(e) die URL noch korrekt an ... :think:
effel
Posts: 542
Joined: 16 Jan 2018, 13:34

Re: Funktionsamnesie?

01 Apr 2021, 18:06

hallo bobo,
wie kommst du an die QAdresse?

Ich nutze die API von 'opencagedata', wenn ich nur einen Stadtnamen übergebe, bekomme ich Weltweit den passenden Code für deine Anwendung.

Brauchst einen Key..


strasse := "Kerpenerstrasse" ; Uniklinik
hausnummer := "62"
postleitzahl := "50937"
ort := "Koeln"

;adresse := strasse ASpace hausnummer ASpace postleitzahl ASpace ort
adresse := ort

GeoData := "https://api.opencagedata.com/geocode/v1/json?q=" adresse "&key=" key "&language=de&pretty=1"


....
},
"wikidata" : "Q365"
},
...


und es kommen noch eine menge Daten dazu

Code: Select all

{
   "documentation" : "https://opencagedata.com/api",
   "licenses" : [
      {
         "name" : "see attribution guide",
         "url" : "https://opencagedata.com/credits"
      }
   ],
   "rate" : {
      "limit" : 2500,
      "remaining" : 2388,
      "reset" : 1617321600
   },
   "results" : [
      {
         "annotations" : {
            "DMS" : {
               "lat" : "50\u00b0 56' 18.09960'' N",
               "lng" : "6\u00b0 57' 35.90640'' E"
            },
            "MGRS" : "32ULB5666844952",
            "Maidenhead" : "JO30lw55ee",
            "Mercator" : {
               "x" : 774780.762,
               "y" : 6577199.623
            },
            "OSM" : {
               "edit_url" : "https://www.openstreetmap.org/edit?relation=62578#map=16/50.93836/6.95997",
               "note_url" : "https://www.openstreetmap.org/note/new#map=16/50.93836/6.95997&layers=N",
               "url" : "https://www.openstreetmap.org/?mlat=50.93836&mlon=6.95997#map=16/50.93836/6.95997"
            },
            "UN_M49" : {
               "regions" : {
                  "DE" : "276",
                  "EUROPE" : "150",
                  "WESTERN_EUROPE" : "155",
                  "WORLD" : "001"
               },
               "statistical_groupings" : [
                  "MEDC"
               ]
            },
            "callingcode" : 49,
            "currency" : {
               "alternate_symbols" : [],
               "decimal_mark" : ",",
               "html_entity" : "&#x20AC;",
               "iso_code" : "EUR",
               "iso_numeric" : "978",
               "name" : "Euro",
               "smallest_denomination" : 1,
               "subunit" : "Cent",
               "subunit_to_unit" : 100,
               "symbol" : "\u20ac",
               "symbol_first" : 0,
               "thousands_separator" : "."
            },
            "flag" : "\ud83c\udde9\ud83c\uddea",
            "geohash" : "u1hcy3h17nsz0mss7uxn",
            "qibla" : 126.73,
            "roadinfo" : {
               "drive_on" : "right",
               "speed_in" : "km/h"
            },
            "sun" : {
               "rise" : {
                  "apparent" : 1617253740,
                  "astronomical" : 1617246780,
                  "civil" : 1617251760,
                  "nautical" : 1617249300
               },
               "set" : {
                  "apparent" : 1617300240,
                  "astronomical" : 1617307260,
                  "civil" : 1617302280,
                  "nautical" : 1617304680
               }
            },
            "timezone" : {
               "name" : "Europe/Berlin",
               "now_in_dst" : 1,
               "offset_sec" : 7200,
               "offset_string" : "+0200",
               "short_name" : "CEST"
            },
            "what3words" : {
               "words" : "t\u00f6pfe.erz\u00e4hlen.gruppe"
            },
            "wikidata" : "Q365"
         },
         "bounds" : {
            "northeast" : {
               "lat" : 51.0849743,
               "lng" : 7.162028
            },
            "southwest" : {
               "lat" : 50.8304399,
               "lng" : 6.7725303
            }
         },
         "components" : {
            "ISO_3166-1_alpha-2" : "DE",
            "ISO_3166-1_alpha-3" : "DEU",
            "_category" : "place",
            "_type" : "city",
            "city" : "K\u00f6ln",
            "continent" : "Europe",
            "country" : "Deutschland",
            "country_code" : "de",
            "political_union" : "European Union",
            "state" : "Nordrhein-Westfalen",
            "state_code" : "NW"
         },
         "confidence" : 4,
         "formatted" : "K\u00f6ln, Nordrhein-Westfalen, Deutschland",
         "geometry" : {
            "lat" : 50.938361,
            "lng" : 6.959974
         }
      },
      {
         "annotations" : {
            "DMS" : {
               "lat" : "49\u00b0 25' 24.51828'' N",
               "lng" : "20\u00b0 18' 27.62676'' E"
            },
            "MGRS" : "34UDV4979274763",
            "Maidenhead" : "KN09dk61wp",
            "Mercator" : {
               "x" : 2260639.94,
               "y" : 6314552.162
            },
            "OSM" : {
               "edit_url" : "https://www.openstreetmap.org/edit?node=3009715161#map=16/49.42348/20.30767",
               "note_url" : "https://www.openstreetmap.org/note/new#map=16/49.42348/20.30767&layers=N",
               "url" : "https://www.openstreetmap.org/?mlat=49.42348&mlon=20.30767#map=16/49.42348/20.30767"
            },
            "UN_M49" : {
               "regions" : {
                  "EASTERN_EUROPE" : "151",
                  "EUROPE" : "150",
                  "PL" : "616",
                  "WORLD" : "001"
               },
               "statistical_groupings" : [
                  "MEDC"
               ]
            },
            "callingcode" : 48,
            "currency" : {
               "alternate_symbols" : [],
               "decimal_mark" : ",",
               "format" : "%n %u",
               "html_entity" : "z&#322;",
               "iso_code" : "PLN",
               "iso_numeric" : "985",
               "name" : "Polish Z\u0142oty",
               "smallest_denomination" : 1,
               "subunit" : "Grosz",
               "subunit_to_unit" : 100,
               "symbol" : "z\u0142",
               "symbol_first" : 0,
               "thousands_separator" : " "
            },
            "flag" : "\ud83c\uddf5\ud83c\uddf1",
            "geohash" : "u2y3nj78e5gmfmjxzyuc",
            "qibla" : 144.05,
            "roadinfo" : {
               "drive_on" : "right",
               "speed_in" : "km/h"
            },
            "sun" : {
               "rise" : {
                  "apparent" : 1617250620,
                  "astronomical" : 1617243900,
                  "civil" : 1617248700,
                  "nautical" : 1617246360
               },
               "set" : {
                  "apparent" : 1617296940,
                  "astronomical" : 1617303720,
                  "civil" : 1617298920,
                  "nautical" : 1617301200
               }
            },
            "timezone" : {
               "name" : "Europe/Warsaw",
               "now_in_dst" : 1,
               "offset_sec" : 7200,
               "offset_string" : "+0200",
               "short_name" : "CEST"
            },
            "what3words" : {
               "words" : "erker.ausw\u00e4rts.erbauten"
            }
         },
         "bounds" : {
            "northeast" : {
               "lat" : 49.4434773,
               "lng" : 20.3276741
            },
            "southwest" : {
               "lat" : 49.4034773,
               "lng" : 20.2876741
            }
         },
         "components" : {
            "ISO_3166-1_alpha-2" : "PL",
            "ISO_3166-1_alpha-3" : "POL",
            "_category" : "place",
            "_type" : "village",
            "continent" : "Europe",
            "country" : "Polen",
            "country_code" : "pl",
            "county" : "powiat nowotarski",
            "hamlet" : "K\u00f6ln",
            "municipality" : "gmina \u0141apsze Ni\u017cne",
            "political_union" : "European Union",
            "postcode" : "34-440",
            "state" : "Woiwodschaft Kleinpolen",
            "village" : "Netzdorf-Burg"
         },
         "confidence" : 7,
         "formatted" : "34-440 Netzdorf-Burg, Polen",
         "geometry" : {
            "lat" : 49.4234773,
            "lng" : 20.3076741
         }
      },
      {
         "annotations" : {
            "DMS" : {
               "lat" : "51\u00b0 13' 26.94792'' N",
               "lng" : "4\u00b0 24' 25.62984'' E"
            },
            "MGRS" : "31UES9825875692",
            "Maidenhead" : "JO21ef83ut",
            "Mercator" : {
               "x" : 490598.287,
               "y" : 6627707.392
            },
            "OSM" : {
               "edit_url" : "https://www.openstreetmap.org/edit?node=1086875193#map=16/51.22415/4.40712",
               "note_url" : "https://www.openstreetmap.org/note/new#map=16/51.22415/4.40712&layers=N",
               "url" : "https://www.openstreetmap.org/?mlat=51.22415&mlon=4.40712#map=16/51.22415/4.40712"
            },
            "UN_M49" : {
               "regions" : {
                  "BE" : "056",
                  "EUROPE" : "150",
                  "WESTERN_EUROPE" : "155",
                  "WORLD" : "001"
               },
               "statistical_groupings" : [
                  "MEDC"
               ]
            },
            "callingcode" : 32,
            "currency" : {
               "alternate_symbols" : [],
               "decimal_mark" : ",",
               "html_entity" : "&#x20AC;",
               "iso_code" : "EUR",
               "iso_numeric" : "978",
               "name" : "Euro",
               "smallest_denomination" : 1,
               "subunit" : "Cent",
               "subunit_to_unit" : 100,
               "symbol" : "\u20ac",
               "symbol_first" : 0,
               "thousands_separator" : "."
            },
            "flag" : "\ud83c\udde7\ud83c\uddea",
            "geohash" : "u155km14m646hfyemxwf",
            "qibla" : 123.91,
            "roadinfo" : {
               "drive_on" : "right",
               "road" : "Stadswaag",
               "speed_in" : "km/h"
            },
            "sun" : {
               "rise" : {
                  "apparent" : 1617254340,
                  "astronomical" : 1617247320,
                  "civil" : 1617252300,
                  "nautical" : 1617249900
               },
               "set" : {
                  "apparent" : 1617300900,
                  "astronomical" : 1617307920,
                  "civil" : 1617302880,
                  "nautical" : 1617305340
               }
            },
            "timezone" : {
               "name" : "Europe/Brussels",
               "now_in_dst" : 1,
               "offset_sec" : 7200,
               "offset_string" : "+0200",
               "short_name" : "CEST"
            },
            "what3words" : {
               "words" : "gewinner.nasen.frohes"
            }
         },
         "bounds" : {
            "northeast" : {
               "lat" : 51.2242022,
               "lng" : 4.4071694
            },
            "southwest" : {
               "lat" : 51.2241022,
               "lng" : 4.4070694
            }
         },
         "components" : {
            "ISO_3166-1_alpha-2" : "BE",
            "ISO_3166-1_alpha-3" : "BEL",
            "_category" : "commerce",
            "_type" : "pub",
            "city" : "Antwerpen",
            "city_district" : "Antwerpen",
            "continent" : "Europe",
            "country" : "Belgien",
            "country_code" : "be",
            "county" : "Antwerpen",
            "county_code" : "VAN",
            "house_number" : "4",
            "neighbourhood" : "Universiteitsbuurt",
            "political_union" : "European Union",
            "postcode" : "2000",
            "pub" : "koln",
            "region" : "Flandern",
            "road" : "Stadswaag",
            "state" : "Antwerpen"
         },
         "confidence" : 9,
         "formatted" : "koln, Stadswaag 4, 2000 Antwerpen, Belgien",
         "geometry" : {
            "lat" : 51.2241522,
            "lng" : 4.4071194
         }
      },
      {
         "annotations" : {
            "DMS" : {
               "lat" : "54\u00b0 50' 1.50468'' N",
               "lng" : "83\u00b0 6' 11.73744'' E"
            },
            "MGRS" : "44UPF3508878318",
            "Maidenhead" : "NO14nu20jc",
            "Mercator" : {
               "x" : 9251012.631,
               "y" : 7294710.384
            },
            "OSM" : {
               "edit_url" : "https://www.openstreetmap.org/edit?node=3285525939#map=16/54.83375/83.10326",
               "note_url" : "https://www.openstreetmap.org/note/new#map=16/54.83375/83.10326&layers=N",
               "url" : "https://www.openstreetmap.org/?mlat=54.83375&mlon=83.10326#map=16/54.83375/83.10326"
            },
            "UN_M49" : {
               "regions" : {
                  "EASTERN_EUROPE" : "151",
                  "EUROPE" : "150",
                  "RU" : "643",
                  "WORLD" : "001"
               },
               "statistical_groupings" : [
                  "MEDC"
               ]
            },
            "callingcode" : 7,
            "currency" : {
               "alternate_symbols" : [
                  "\u0440\u0443\u0431.",
                  "\u0440."
               ],
               "decimal_mark" : ",",
               "format" : "%n %u",
               "html_entity" : "&#x20BD;",
               "iso_code" : "RUB",
               "iso_numeric" : "643",
               "name" : "Russian Ruble",
               "smallest_denomination" : 1,
               "subunit" : "Kopeck",
               "subunit_to_unit" : 100,
               "symbol" : "\u20bd",
               "symbol_first" : 0,
               "thousands_separator" : "."
            },
            "flag" : "\ud83c\uddf7\ud83c\uddfa",
            "geohash" : "vcepgn1vy245rjv1sg44",
            "qibla" : 241.7,
            "roadinfo" : {
               "drive_on" : "right",
               "road" : "\u0443\u043b\u0438\u0446\u0430 \u0423\u0447\u0451\u043d\u044b\u0445",
               "speed_in" : "km/h"
            },
            "sun" : {
               "rise" : {
                  "apparent" : 1617235260,
                  "astronomical" : 1617313920,
                  "civil" : 1617319500,
                  "nautical" : 1617316800
               },
               "set" : {
                  "apparent" : 1617282180,
                  "astronomical" : 1617290040,
                  "civil" : 1617284400,
                  "nautical" : 1617287100
               }
            },
            "timezone" : {
               "name" : "Asia/Novosibirsk",
               "now_in_dst" : 0,
               "offset_sec" : 25200,
               "offset_string" : "+0700",
               "short_name" : "+07"
            },
            "what3words" : {
               "words" : "geistliches.entdeckst.insofern"
            }
         },
         "bounds" : {
            "northeast" : {
               "lat" : 54.8338013,
               "lng" : 83.1033104
            },
            "southwest" : {
               "lat" : 54.8337013,
               "lng" : 83.1032104
            }
         },
         "components" : {
            "ISO_3166-1_alpha-2" : "RU",
            "ISO_3166-1_alpha-3" : "RUS",
            "_category" : "commerce",
            "_type" : "pub",
            "city" : "Nowosibirsk",
            "city_district" : "\u0421\u043e\u0432\u0435\u0442\u0441\u043a\u0438\u0439 \u0440\u0430\u0439\u043e\u043d",
            "continent" : "Asia",
            "country" : "Russland",
            "country_code" : "ru",
            "postcode" : "630090",
            "pub" : "\u041a\u0451\u043b\u044c\u043d",
            "region" : "F\u00f6derationskreis Sibirien",
            "road" : "\u0443\u043b\u0438\u0446\u0430 \u0423\u0447\u0451\u043d\u044b\u0445",
            "state" : "Oblast Nowosibirsk",
            "suburb" : "\u0412\u0435\u0440\u0445\u043d\u044f\u044f \u0437\u043e\u043d\u0430"
         },
         "confidence" : 9,
         "formatted" : "\u041a\u0451\u043b\u044c\u043d, \u0443\u043b\u0438\u0446\u0430 \u0423\u0447\u0451\u043d\u044b\u0445, \u0412\u0435\u0440\u0445\u043d\u044f\u044f \u0437\u043e\u043d\u0430, Nowosibirsk, Oblast Nowosibirsk, Russland, 630090",
         "geometry" : {
            "lat" : 54.8337513,
            "lng" : 83.1032604
         }
      },
      {
         "annotations" : {
            "DMS" : {
               "lat" : "52\u00b0 50' 21.14988'' N",
               "lng" : "1\u00b0 14' 36.96504'' E"
            },
            "MGRS" : "31UCU8169455829",
            "Maidenhead" : "JO02ou91fj",
            "Mercator" : {
               "x" : 138437.07,
               "y" : 6919235.034
            },
            "OSM" : {
               "edit_url" : "https://www.openstreetmap.org/edit?way=595873768#map=16/52.83921/1.24360",
               "note_url" : "https://www.openstreetmap.org/note/new#map=16/52.83921/1.24360&layers=N",
               "url" : "https://www.openstreetmap.org/?mlat=52.83921&mlon=1.24360#map=16/52.83921/1.24360"
            },
            "UN_M49" : {
               "regions" : {
                  "EUROPE" : "150",
                  "GB" : "826",
                  "NORTHERN_EUROPE" : "154",
                  "WORLD" : "001"
               },
               "statistical_groupings" : [
                  "MEDC"
               ]
            },
            "callingcode" : 44,
            "currency" : {
               "alternate_symbols" : [],
               "decimal_mark" : ".",
               "html_entity" : "&#x00A3;",
               "iso_code" : "GBP",
               "iso_numeric" : "826",
               "name" : "British Pound",
               "smallest_denomination" : 1,
               "subunit" : "Penny",
               "subunit_to_unit" : 100,
               "symbol" : "\u00a3",
               "symbol_first" : 1,
               "thousands_separator" : ","
            },
            "flag" : "\ud83c\uddec\ud83c\udde7",
            "geohash" : "u12us71ddn26upz0vtcs",
            "qibla" : 121.75,
            "roadinfo" : {
               "drive_on" : "left",
               "road" : "The Loke",
               "speed_in" : "mph"
            },
            "sun" : {
               "rise" : {
                  "apparent" : 1617255000,
                  "astronomical" : 1617247620,
                  "civil" : 1617252900,
                  "nautical" : 1617250380
               },
               "set" : {
                  "apparent" : 1617301740,
                  "astronomical" : 1617309120,
                  "civil" : 1617303840,
                  "nautical" : 1617306360
               }
            },
            "timezone" : {
               "name" : "Europe/London",
               "now_in_dst" : 1,
               "offset_sec" : 3600,
               "offset_string" : "+0100",
               "short_name" : "BST"
            },
            "what3words" : {
               "words" : "revue.ding.rehe"
            }
         },
         "bounds" : {
            "northeast" : {
               "lat" : 52.8392632,
               "lng" : 1.2436537
            },
            "southwest" : {
               "lat" : 52.8391535,
               "lng" : 1.2435491
            }
         },
         "components" : {
            "ISO_3166-1_alpha-2" : "GB",
            "ISO_3166-1_alpha-3" : "GBR",
            "_category" : "building",
            "_type" : "building",
            "building" : "Koln",
            "city" : "Norwich",
            "continent" : "Europe",
            "country" : "Vereinigtes K\u00f6nigreich",
            "country_code" : "gb",
            "county" : "Norfolk",
            "county_code" : "NFK",
            "house_number" : "2",
            "postcode" : "NR11 7QW",
            "road" : "The Loke",
            "state" : "England",
            "state_code" : "ENG",
            "state_district" : "East of England",
            "suburb" : "Erpingham",
            "village" : "Calthorpe"
         },
         "confidence" : 10,
         "formatted" : "Koln, 2 The Loke, Calthorpe NR11 7QW, Vereinigtes K\u00f6nigreich",
         "geometry" : {
            "lat" : 52.8392083,
            "lng" : 1.2436014
         }
      }
   ],
   "status" : {
      "code" : 200,
      "message" : "OK"
   },
   "stay_informed" : {
      "blog" : "https://blog.opencagedata.com",
      "twitter" : "https://twitter.com/OpenCage"
   },
   "thanks" : "For using an OpenCage API",
   "timestamp" : {
      "created_http" : "Thu, 01 Apr 2021 12:07:09 GMT",
      "created_unix" : 1617278829
   },
   "total_results" : 5
}
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Funktionsamnesie?

02 Apr 2021, 13:48

effel wrote:
01 Apr 2021, 18:06
hallo bobo,
wie kommst du an die QAdresse? Allgemeinere Abfragen, wie zB die regionale Suche liefert Daten, in welchen die Q# enthalten sind.
Alternativ gehts auch über ein Fundstück aus dem Web: https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&ppprop=wikibase_item&redirects=1&format=json&titles=Berlin. HTH :)

Return to “Ich brauche Hilfe”

Who is online

Users browsing this forum: No registered users and 28 guests