Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
weather-on-the-slash
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
weather-on-the-slash
Commits
f4bbb865
Commit
f4bbb865
authored
9 years ago
by
ryadav88
Browse files
Options
Downloads
Patches
Plain Diff
index
parent
8699f0e8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
index.js
+14
-8
14 additions, 8 deletions
index.js
with
14 additions
and
8 deletions
index.js
+
14
−
8
View file @
f4bbb865
...
@@ -4,32 +4,36 @@ var url = require('url');
...
@@ -4,32 +4,36 @@ var url = require('url');
var
request
=
require
(
'
request
'
);
var
request
=
require
(
'
request
'
);
var
format
=
"
.json
"
;
var
format
=
"
.json
"
;
var
apikey
=
process
.
env
.
WU_ACCESS
var
apikey
=
process
.
env
.
WU_ACCESS
//WU API key; will be set in Heroku
var
bodyParser
=
require
(
'
body-parser
'
);
var
bodyParser
=
require
(
'
body-parser
'
);
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
//use port is set in the environment variable, or 9001 if it isn’t set.
app
.
set
(
'
port
'
,
(
process
.
env
.
PORT
||
9001
));
app
.
set
(
'
port
'
,
(
process
.
env
.
PORT
||
9001
));
//for testing that the app is running
app
.
get
(
'
/
'
,
function
(
req
,
res
){
app
.
get
(
'
/
'
,
function
(
req
,
res
){
res
.
send
(
'
It works
!
'
);
res
.
send
(
'
Running!
!
'
);
});
});
//app.post is triggered when a POST request is sent to the URL ‘/post’
app
.
post
(
'
/post
'
,
function
(
req
,
res
){
app
.
post
(
'
/post
'
,
function
(
req
,
res
){
//take a message from Slack slash command
var
query
=
req
.
body
.
text
var
query
=
req
.
body
.
text
var
parsed_url
=
url
.
format
({
var
parsed_url
=
url
.
format
({
pathname
:
'
http://api.wunderground.com/api/
'
+
apikey
+
'
/conditions/q/
'
+
req
.
body
.
text
+
format
,
pathname
:
'
http://api.wunderground.com/api/
'
+
apikey
+
'
/conditions/q/
'
+
req
.
body
.
text
+
format
,
});
});
console
.
log
(
parsed_url
);
console
.
log
(
parsed_url
);
request
(
parsed_url
,
function
(
error
,
response
,
body
)
{
request
(
parsed_url
,
function
(
error
,
response
,
body
)
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
var
data
=
JSON
.
parse
(
body
);
var
data
=
JSON
.
parse
(
body
);
var
first_
ur
l
=
data
.
current_observation
.
temperature_string
;
var
temperat
ur
e
=
data
.
current_observation
.
temperature_string
;
var
weatherC
=
data
.
current_observation
.
weather
var
weatherC
ondition
=
data
.
current_observation
.
weather
var
icon_url
=
data
.
current_observation
.
icon_url
var
icon_url
=
data
.
current_observation
.
icon_url
var
location
=
data
.
current_observation
.
display_location
.
full
var
location
=
data
.
current_observation
.
display_location
.
full
...
@@ -37,17 +41,19 @@ app.post('/post', function(req, res){
...
@@ -37,17 +41,19 @@ app.post('/post', function(req, res){
response_type
:
"
in_channel
"
,
response_type
:
"
in_channel
"
,
"
attachments
"
:
[
"
attachments
"
:
[
{
{
"
text
"
:
"
Location:
"
+
location
+
"
\n
"
+
"
Temperature:
"
+
first_url
+
"
\n
"
+
"
Condition:
"
+
weatherC
,
"
text
"
:
"
Location:
"
+
location
+
"
\n
"
"
image_url
"
:
icon_url
,
+
"
Temperature:
"
+
temperature
+
"
\n
"
+
"
Condition:
"
+
weatherCondition
,
"
image_url
"
:
icon_url
,
}
}
]
]
};
};
res
.
send
(
body
);
res
.
send
(
body
);
}
}
});
});
});
});
//tells Node which port to listen on
app
.
listen
(
app
.
get
(
'
port
'
),
function
()
{
app
.
listen
(
app
.
get
(
'
port
'
),
function
()
{
console
.
log
(
'
Node app is running on port
'
,
app
.
get
(
'
port
'
));
console
.
log
(
'
Node app is running on port
'
,
app
.
get
(
'
port
'
));
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment