-
Notifications
You must be signed in to change notification settings - Fork 1
/
scripts.js
executable file
·106 lines (78 loc) · 2.9 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var weather;
var lat;
var lon;
var city;
$(function() {
// write a function to go get the weather
var goGetTheWeather = function(city){
var encodedCity = encodeURI(city);
$.ajax('http://api.wunderground.com/api/a637745210e001ef/conditions/q/'+ encodedCity +'.json',{
type : 'GET',
dataType : 'jsonp',
success : function(data){
//if there is no data observation
// ! means if there is no (not)
if(!data.current_observation) {
$('h1.weather').text("Please be more specific");
return false; //abandon all ship
}
var w = data.current_observation;
weather = w.weather;
var location = w.display_location.full;
var tempF = w.temp_f;
var tempC = w.temp_c;
lat = w.observation_location.latitude;
lon = w.observation_location.longitude;
var locString = location;
var weatherString = weather;
var tempString = tempF + " F" + " / " + tempC + " C";
$("p.location").text(locString);
$("p.weather").text(weatherString);
$("p.tempFC").text(tempString);
getTwit();
jsonFlickrApi();
} //object close
}); //end ajax
}; //end function weatherFeels
$(".cityForm").on("submit", function(e){
e.preventDefault();
city = $('input[name="city"]').val();
goGetTheWeather(city);
}); //end Form stuff
var getTwit = function(){
alert("we got this far");
$.ajax("http://noauth.jit.su/1.1/search/tweets.json?q=" + weather + "&geocode=" + lat + "," + lon + "," + "50mi" + "&count=20" + "&result_type=popular" + "%23dlws",{
type : 'GET',
dataType : 'jsonp',
success : function(twitterdata){
if(!twitterdata.statuses) {
$('h1').text("Oh such sad, this city doesn't tweet enough. But you can still see the weather...");
return false; //abandon all ship
}
var t = twitterdata.statuses;
var tweet = t[Math.floor((Math.random()*t.length))].text;
$("h1").fadeIn("slow", function(){
$("h1").text(tweet);
$("h1").addClass("h1Back");
}); //fadeIn tweet
// var googlePhoto = "http://maps.googleapis.com/maps/api/streetview?size=1000x800&location=" + encodeURI(city) + "&sensor=false&fov=120&pitch=10";
// console.log(googlePhoto);
// $("body").css({
// "background-image": "url(" + googlePhoto + ")",
// "background-size" : "cover",
// "background-position" : "center",
// "background-repeat" : "no-repeat",
// });
} // function(twitterdata)
}); //end twit ajax
}; // getTwit'
var jsonFlickrApi = function(){
$.ajax("https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=e33074ace6154eb96a87b3cee46a906c&tags=&secret=462cfa7baff67641" + weather + "&has_geo=1&lat=" + lat + "&lon=" + lon + "&format=json",{
type: "GET",
dataType: "jsonp",
success: function(){
console.log(data);
}
}); //end flickr photo
}; //end flickr function
}); //document ready