{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Dependencies and Setup\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import requests\n",
    "import time\n",
    "from scipy.stats import linregress\n",
    "import pprint\n",
    "import json\n",
    "\n",
    "# # Incorporated citipy to determine city based on latitude and longitude\n",
    "from citipy import citipy\n",
    "\n",
    "# Output File (CSV)\n",
    "output_data_file = \"output_data/cities.csv\"\n",
    "\n",
    "# Range of latitudes and longitudes\n",
    "lat_range = (-90, 90)\n",
    "lng_range = (-180, 180)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "86936940bb80c340d7e1b78187213217\n"
     ]
    }
   ],
   "source": [
    "from api_keys import weather_api_key\n",
    "print(weather_api_key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Weatther is {'coord': {'lon': -68.5914, 'lat': 70.4692}, 'weather': [{'id': 802, 'main': 'Clouds', 'description': 'scattered clouds', 'icon': '03n'}], 'base': 'stations', 'main': {'temp': -27, 'feels_like': -32.26, 'temp_min': -27, 'temp_max': -27, 'pressure': 1027, 'humidity': 83}, 'visibility': 10000, 'wind': {'speed': 2.06, 'deg': 230}, 'clouds': {'all': 40}, 'dt': 1611861478, 'sys': {'type': 1, 'id': 776, 'country': 'CA', 'sunrise': 1611845494, 'sunset': 1611859377}, 'timezone': -18000, 'id': 5924351, 'name': 'Clyde River', 'cod': 200}\n",
      "http://api.openweathermap.org/data/2.5/weather?appid=86936940bb80c340d7e1b78187213217&q=clyde river&units=metric\n"
     ]
    }
   ],
   "source": [
    "units = \"metric\"\n",
    "url = \"http://api.openweathermap.org/data/2.5/weather?\"\n",
    "cities3 = \"Austin\"\n",
    "query_url1 = f\"{url}appid={weather_api_key}&q={city}&units={units}\"\n",
    "weather_response = requests.get(query_url1)\n",
    "weather_json = weather_response.json() \n",
    "print (f\"The Weatther is {weather_json}\")\n",
    "print(query_url1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "638"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# List for holding lat_lngs and cities\n",
    "lat_lngs = []\n",
    "cities = []\n",
    "\n",
    "# Create a set of random lat and lng combinations\n",
    "lats = np.random.uniform(lat_range[0], lat_range[1], size=1500)\n",
    "lngs = np.random.uniform(lng_range[0], lng_range[1], size=1500)\n",
    "lat_lngs = zip(lats, lngs)\n",
    "\n",
    "# Identify nearest city for each lat, lng combination\n",
    "for lat_lng in lat_lngs:\n",
    "    city = citipy.nearest_city(lat_lng[0], lat_lng[1]).city_name\n",
    "    \n",
    "    # If the city is unique, then add it to a our cities list\n",
    "    if city not in cities:\n",
    "        cities.append(city)\n",
    "\n",
    "# Print the city count to confirm sufficient count\n",
    "len(cities)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "lat = []\n",
    "temp = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "chokurdakh found!\n",
      "barrow found!\n",
      "ushuaia found!\n",
      "nikolskoye found!\n",
      "bambous virieux found!\n",
      "hermanus found!\n",
      "puerto ayora found!\n",
      "englehart found!\n",
      "ribeira grande found!\n",
      "busselton found!\n",
      "bengkulu found!\n",
      "rikitea found!\n",
      "ahipara found!\n",
      "lorengau found!\n",
      "los rastrojos found!\n",
      "thompson found!\n",
      "mahebourg found!\n",
      "ostrovnoy found!\n",
      "tuktoyaktuk found!\n",
      "tezu found!\n",
      "liverpool found!\n",
      "anloga found!\n",
      "avarua found!\n",
      "lavrentiya found!\n",
      "hasaki found!\n",
      "norman wells found!\n",
      "barentsburg found!\n",
      "qaanaaq found!\n",
      "amderma found!\n",
      "merauke found!\n",
      "tasiilaq found!\n",
      "bilibino found!\n",
      "port alfred found!\n",
      "dingle found!\n",
      "cordoba found!\n",
      "dikson found!\n",
      "krzeszowice found!\n",
      "mar del plata found!\n",
      "katsuura found!\n",
      "ugoofaaru found!\n",
      "samalaeulu found!\n",
      "paamiut found!\n",
      "yumen found!\n",
      "jardim found!\n",
      "alice springs found!\n",
      "jamestown found!\n",
      "rudbar found!\n",
      "sahrak found!\n",
      "naze found!\n",
      "kayerkan found!\n",
      "sur found!\n",
      "jumla found!\n",
      "rondonopolis found!\n",
      "pisco found!\n",
      "togul found!\n",
      "portland found!\n",
      "iranshahr found!\n",
      "taolanaro found!\n",
      "buluang found!\n",
      "pagudpud found!\n",
      "okhotsk found!\n",
      "banes found!\n",
      "yellowknife found!\n",
      "cerrito found!\n",
      "kaitangata found!\n",
      "ponta do sol found!\n",
      "constitucion found!\n",
      "anito found!\n",
      "mirpur mathelo found!\n",
      "ancud found!\n",
      "kodiak found!\n",
      "beringovskiy found!\n",
      "tiksi found!\n",
      "mataura found!\n",
      "ilulissat found!\n",
      "grand centre found!\n",
      "punta arenas found!\n",
      "dhidhdhoo found!\n",
      "weligama found!\n",
      "san carlos de bariloche found!\n",
      "tsumeb found!\n",
      "makakilo city found!\n",
      "olafsvik found!\n",
      "grand-santi found!\n",
      "hay river found!\n",
      "kapaa found!\n",
      "dawei found!\n",
      "hithadhoo found!\n",
      "maryborough found!\n",
      "luderitz found!\n",
      "mahadday weyne found!\n",
      "bluff found!\n",
      "vardo found!\n",
      "la asuncion found!\n",
      "sibolga found!\n",
      "ilam found!\n",
      "hokitika found!\n",
      "flinders found!\n",
      "new norfolk found!\n",
      "carnarvon found!\n",
      "san bartolome de tirajana found!\n",
      "aberystwyth found!\n",
      "kudahuvadhoo found!\n",
      "burica found!\n",
      "sao joao da barra found!\n",
      "arraial do cabo found!\n",
      "belushya guba found!\n",
      "marsa matruh found!\n",
      "saint-philippe found!\n",
      "bonthe found!\n",
      "san patricio found!\n",
      "prince rupert found!\n",
      "ambodifototra found!\n",
      "karangampel found!\n",
      "nanortalik found!\n",
      "harnosand found!\n",
      "saldanha found!\n",
      "broken hill found!\n",
      "maniitsoq found!\n",
      "acapulco found!\n",
      "sterling found!\n",
      "tsihombe found!\n",
      "vaini found!\n",
      "tabat found!\n",
      "east london found!\n",
      "polunochnoye found!\n",
      "grand gaube found!\n",
      "surt found!\n",
      "georgetown found!\n",
      "mys shmidta found!\n",
      "torquay found!\n",
      "sentyabrskiy found!\n",
      "cocula found!\n",
      "la palma found!\n",
      "belaya gora found!\n",
      "nerchinskiy zavod found!\n",
      "olindina found!\n",
      "kuche found!\n",
      "cape town found!\n",
      "paita found!\n",
      "albany found!\n",
      "torbay found!\n",
      "broome found!\n",
      "grand river south east found!\n",
      "vanimo found!\n",
      "chuy found!\n",
      "kavieng found!\n",
      "moscow found!\n",
      "atuona found!\n",
      "hobart found!\n",
      "wad madani found!\n",
      "marcona found!\n",
      "ampanihy found!\n",
      "mount isa found!\n",
      "cherskiy found!\n",
      "te anau found!\n",
      "bredasdorp found!\n",
      "zeya found!\n",
      "gornopravdinsk found!\n",
      "prudnik found!\n",
      "geraldton found!\n",
      "haines junction found!\n",
      "agua dulce found!\n",
      "acajutla found!\n",
      "shaartuz found!\n",
      "puerto baquerizo moreno found!\n",
      "shizunai found!\n",
      "poum found!\n",
      "zhezkazgan found!\n",
      "toro found!\n",
      "graham found!\n",
      "port blair found!\n",
      "hilo found!\n",
      "gat found!\n",
      "sioux lookout found!\n",
      "mayo found!\n",
      "dunedin found!\n",
      "loni found!\n",
      "catia la mar found!\n",
      "saskylakh found!\n",
      "upernavik found!\n",
      "iqaluit found!\n",
      "leningradskiy found!\n",
      "nizhneyansk found!\n",
      "brahmapuri found!\n",
      "goderich found!\n",
      "ouadda found!\n",
      "ouro preto do oeste found!\n",
      "port macquarie found!\n",
      "pimentel found!\n",
      "esperance found!\n",
      "khatanga found!\n",
      "taitung found!\n",
      "karkaralinsk found!\n",
      "krasnoselkup found!\n",
      "bacolod found!\n",
      "guerrero negro found!\n",
      "nome found!\n",
      "castro found!\n",
      "diego de almagro found!\n",
      "lazaro cardenas found!\n",
      "korocha found!\n",
      "santarem found!\n",
      "vaitupu found!\n",
      "palabuhanratu found!\n",
      "dolores found!\n",
      "pinawa found!\n",
      "oyama found!\n",
      "kavaratti found!\n",
      "waingapu found!\n",
      "vila do maio found!\n",
      "otradnoye found!\n",
      "svetlogorsk found!\n",
      "shypyntsi found!\n",
      "umzimvubu found!\n",
      "voh found!\n",
      "faanui found!\n",
      "hofn found!\n",
      "coihaique found!\n",
      "gondanglegi found!\n",
      "umreth found!\n",
      "rio gallegos found!\n",
      "oranjemund found!\n",
      "fortuna found!\n",
      "limon found!\n",
      "san rafael found!\n",
      "talnakh found!\n",
      "longyearbyen found!\n",
      "manoel urbano found!\n",
      "illoqqortoormiut found!\n",
      "victoria found!\n",
      "kirakira found!\n",
      "cabo san lucas found!\n",
      "tapes found!\n",
      "formoso do araguaia found!\n",
      "neuquen found!\n",
      "waipawa found!\n",
      "ruatoria found!\n",
      "taltal found!\n",
      "fort-shevchenko found!\n",
      "kaoma found!\n",
      "cidreira found!\n",
      "marzuq found!\n",
      "mezhdurechensk found!\n",
      "port alberni found!\n",
      "kalmar found!\n",
      "puerto boyaca found!\n",
      "trinidad found!\n",
      "slave lake found!\n",
      "hunchun found!\n",
      "richards bay found!\n",
      "ponta delgada found!\n",
      "seybaplaya found!\n",
      "hervey bay found!\n",
      "alofi found!\n",
      "breves found!\n",
      "pevek found!\n",
      "orlea found!\n",
      "tobermory found!\n",
      "gorno-chuyskiy found!\n",
      "formiga found!\n",
      "sabzevar found!\n",
      "opuwo found!\n",
      "aksu found!\n",
      "port shepstone found!\n",
      "butaritari found!\n",
      "cam ranh found!\n",
      "esmeralda found!\n",
      "port elizabeth found!\n",
      "mathathane found!\n",
      "farafangana found!\n",
      "saleaula found!\n",
      "henties bay found!\n",
      "pochutla found!\n",
      "zarnovica found!\n",
      "north platte found!\n",
      "tura found!\n",
      "formosa do rio preto found!\n",
      "saint anthony found!\n",
      "adrar found!\n",
      "yulara found!\n",
      "homer found!\n",
      "lavumisa found!\n",
      "asyut found!\n",
      "kalmunai found!\n",
      "port hardy found!\n",
      "teresina found!\n",
      "bhuj found!\n",
      "hare bay found!\n",
      "ambilobe found!\n",
      "ixtapa found!\n",
      "airai found!\n",
      "leshan found!\n",
      "dublin found!\n",
      "pacific grove found!\n",
      "bandarbeyla found!\n",
      "smolenka found!\n",
      "tazovskiy found!\n",
      "sitka found!\n",
      "sobolevo found!\n",
      "sidi ali found!\n",
      "vestmannaeyjar found!\n",
      "northam found!\n",
      "east stroudsburg found!\n",
      "aklavik found!\n",
      "deputatskiy found!\n",
      "grindavik found!\n",
      "terracina found!\n",
      "kahului found!\n",
      "yetkul found!\n",
      "kangaatsiaq found!\n",
      "bethel found!\n",
      "nyurba found!\n",
      "sao francisco de paula found!\n",
      "carauari found!\n",
      "olinda found!\n",
      "kapit found!\n",
      "atar found!\n",
      "babanusah found!\n",
      "yar-sale found!\n",
      "russell found!\n",
      "qandala found!\n",
      "tual found!\n",
      "urdzhar found!\n",
      "narsaq found!\n",
      "oranjestad found!\n",
      "soyo found!\n",
      "camacha found!\n",
      "iquique found!\n",
      "yurgamysh found!\n",
      "peniche found!\n",
      "santa maria found!\n",
      "bantry found!\n",
      "namibe found!\n",
      "palmerston north found!\n",
      "college found!\n",
      "port hedland found!\n",
      "avera found!\n",
      "yanam found!\n",
      "souillac found!\n",
      "ekhabi found!\n",
      "jaipur hat found!\n",
      "pucallpa found!\n",
      "manaure found!\n",
      "rungata found!\n",
      "tuggurt found!\n",
      "vao found!\n",
      "hanzhong found!\n",
      "aykhal found!\n",
      "nemuro found!\n",
      "san cristobal found!\n",
      "machali found!\n",
      "hamilton found!\n",
      "buchanan found!\n",
      "preobrazheniye found!\n",
      "kualakapuas found!\n",
      "lomovka found!\n",
      "awjilah found!\n",
      "warrnambool found!\n",
      "katangli found!\n",
      "clyde river found!\n",
      "lompoc found!\n",
      "hammerfest found!\n",
      "hailun found!\n",
      "belyy yar found!\n",
      "harindanga found!\n",
      "longlac found!\n",
      "pasighat found!\n",
      "ryde found!\n",
      "halalo found!\n",
      "shellbrook found!\n",
      "kiambu found!\n",
      "provideniya found!\n",
      "mount pleasant found!\n",
      "laguna found!\n",
      "nanhai found!\n",
      "lethem found!\n",
      "ranong found!\n",
      "codrington found!\n",
      "stari kuty found!\n",
      "libreville found!\n",
      "bilma found!\n",
      "greece found!\n",
      "tumannyy found!\n",
      "lasa found!\n",
      "el alto found!\n",
      "governador valadares found!\n",
      "inongo found!\n",
      "riberalta found!\n",
      "rio blanco found!\n",
      "touros found!\n",
      "salalah found!\n",
      "yabrud found!\n",
      "syedove found!\n",
      "nouakchott found!\n",
      "makat found!\n",
      "iwaki found!\n",
      "larsnes found!\n",
      "codo found!\n",
      "bekovo found!\n",
      "kitob found!\n",
      "isangel found!\n",
      "attawapiskat found!\n",
      "solsvik found!\n",
      "roald found!\n",
      "komsomolskiy found!\n",
      "sao filipe found!\n",
      "turukhansk found!\n",
      "sorbhog found!\n",
      "bemidji found!\n",
      "meiganga found!\n",
      "robertsport found!\n",
      "matamoros found!\n",
      "odweyne found!\n",
      "klaksvik found!\n",
      "tutoia found!\n",
      "farmington found!\n",
      "puerto escondido found!\n",
      "karamea found!\n",
      "mount gambier found!\n",
      "erzin found!\n",
      "yarada found!\n",
      "giyani found!\n",
      "sorland found!\n",
      "chikoy found!\n",
      "guadalupe y calvo found!\n",
      "morro bay found!\n",
      "gagnoa found!\n",
      "jijiga found!\n",
      "dalby found!\n",
      "jinka found!\n",
      "port augusta found!\n",
      "orillia found!\n",
      "tessalit found!\n",
      "moundsville found!\n",
      "buraydah found!\n",
      "yartsevo found!\n",
      "saint-francois found!\n",
      "pangai found!\n",
      "bulgan found!\n",
      "sao jose do egito found!\n",
      "gwanda found!\n",
      "canita found!\n",
      "korla found!\n",
      "saint george found!\n",
      "kyabe found!\n",
      "jiddah found!\n",
      "palmer found!\n",
      "meyungs found!\n",
      "severobaykalsk found!\n",
      "batemans bay found!\n",
      "havelock found!\n",
      "itamaraca found!\n",
      "capao da canoa found!\n",
      "aquiraz found!\n",
      "luwuk found!\n",
      "sfantu gheorghe found!\n",
      "fuyu found!\n",
      "kruisfontein found!\n",
      "gazanjyk found!\n",
      "micheweni found!\n",
      "najran found!\n",
      "nhulunbuy found!\n",
      "bam found!\n",
      "gayeri found!\n",
      "marang found!\n",
      "kasane found!\n",
      "lusambo found!\n",
      "westport found!\n",
      "ranibennur found!\n",
      "birjand found!\n",
      "santa cruz das palmeiras found!\n",
      "negombo found!\n",
      "bathsheba found!\n",
      "rawson found!\n",
      "ambon found!\n",
      "tibiri found!\n",
      "vasarosnameny found!\n",
      "dhangadhi found!\n",
      "angoche found!\n",
      "aswan found!\n",
      "tunceli found!\n",
      "rocha found!\n",
      "mecca found!\n",
      "svirsk found!\n",
      "port lincoln found!\n",
      "kieta found!\n",
      "batticaloa found!\n",
      "inhuma found!\n",
      "tranas found!\n",
      "sloboda found!\n",
      "amapa found!\n",
      "marienburg found!\n",
      "wilhelmshaven found!\n",
      "comodoro rivadavia found!\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "umm lajj found!\n",
      "huaihua found!\n",
      "skjervoy found!\n",
      "geylegphug found!\n",
      "nicoya found!\n",
      "high level found!\n",
      "pierre found!\n",
      "sao paulo de olivenca found!\n",
      "malwan found!\n",
      "la rioja found!\n",
      "boende found!\n",
      "lagoa found!\n",
      "adre found!\n",
      "agadez found!\n",
      "innisfail found!\n",
      "katherine found!\n",
      "mogapi found!\n",
      "ewa beach found!\n",
      "cockburn town found!\n",
      "tari found!\n",
      "fevralsk found!\n",
      "samusu found!\n",
      "shimoda found!\n",
      "etne found!\n",
      "collipulli found!\n",
      "kamphaeng phet found!\n",
      "shubarkuduk found!\n",
      "lamu found!\n",
      "camacupa found!\n",
      "calvia found!\n",
      "kjollefjord found!\n",
      "koronowo found!\n",
      "khetri found!\n",
      "kailua found!\n",
      "svetlaya found!\n",
      "itoman found!\n",
      "meulaboh found!\n",
      "mixtequilla found!\n",
      "targsorul-vechi found!\n",
      "juifang found!\n",
      "marrakesh found!\n",
      "arrecife found!\n",
      "la ronge found!\n",
      "barpathar found!\n",
      "seoul found!\n",
      "vila velha found!\n",
      "kilindoni found!\n",
      "talara found!\n",
      "brae found!\n",
      "suao found!\n",
      "bargal found!\n",
      "auki found!\n",
      "hakodate found!\n",
      "menongue found!\n",
      "muros found!\n",
      "la libertad found!\n",
      "svetlyy found!\n",
      "husavik found!\n",
      "dakoro found!\n",
      "shar found!\n",
      "karachi found!\n",
      "iztapa found!\n",
      "padang found!\n",
      "severo-kurilsk found!\n",
      "santiago de cuba found!\n",
      "nangwa found!\n",
      "solnechnyy found!\n",
      "gavle found!\n",
      "hambantota found!\n",
      "ejido found!\n",
      "tingo maria found!\n",
      "tabou found!\n",
      "kita found!\n",
      "lolua found!\n",
      "bosaso found!\n",
      "evensk found!\n",
      "oktyabrskiy found!\n",
      "raudeberg found!\n",
      "tuatapere found!\n",
      "aflu found!\n",
      "spornoye found!\n",
      "kasungu found!\n",
      "temaraia found!\n",
      "waitati found!\n",
      "khurianwala found!\n",
      "lima found!\n",
      "sambava found!\n",
      "mettet found!\n",
      "ayan found!\n",
      "la tuque found!\n",
      "batagay found!\n",
      "gejiu found!\n",
      "sao gabriel da cachoeira found!\n",
      "tsogni found!\n",
      "birin found!\n",
      "mandera found!\n",
      "repnoye found!\n",
      "hasan abdal found!\n",
      "srednekolymsk found!\n",
      "aleppo found!\n",
      "saint-pierre found!\n",
      "ifakara found!\n",
      "khani found!\n",
      "kizukuri found!\n",
      "pitimbu found!\n",
      "telimele found!\n",
      "zapolyarnyy found!\n",
      "zyryanka found!\n",
      "lata found!\n",
      "rincon found!\n",
      "virginia beach found!\n",
      "morant bay found!\n",
      "matara found!\n",
      "ribas do rio pardo found!\n",
      "liure found!\n",
      "ulaanbaatar found!\n",
      "jiangkou found!\n",
      "bull savanna found!\n",
      "kununurra found!\n",
      "louisbourg found!\n",
      "tilichiki found!\n",
      "redmond found!\n",
      "barbosa ferraz found!\n",
      "north las vegas found!\n",
      "vincennes found!\n",
      "papara found!\n",
      "bundaberg found!\n"
     ]
    }
   ],
   "source": [
    "for city in cities:\n",
    "    weather_response = requests.get(query_url1).json()\n",
    "    try:\n",
    "        lat.append(weather_response['coord']['lat'])\n",
    "        temp.append(weather_response['main']['temp'])\n",
    "        print(f\"{city} found!\")\n",
    "    except KeyError:\n",
    "        print(f\"We can't find {city}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
