Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Instagram script to fetch images for a given hash tag #1150

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/scripts/instagram.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Description:
# gets photos of hash tag
#
# Dependencies:
# "instagram-node-lib": "*"
#
# Configuration:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it obvious where to get these? Might include any notes or URLs for easily finding these.

# HUBOT_INSTAGRAM_CLIENT_KEY
# HUBOT_INSTAGRAM_ACCESS_KEY
#
# Commands:
# hubot insta tag <tag> <count>- Show recent instagram tags
# by default count is 1
#
# Author:
# raysrashmi
#

config =
client_key: process.env.HUBOT_INSTAGRAM_CLIENT_KEY
client_secret: process.env.HUBOT_INSTAGRAM_ACCESS_KEY

Instagram = require('instagram-node-lib')
Instagram.set('client_id', config.client_key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if config.client_key isn't set in the environment? does Instagram complain? If it does, should consider moving this to the authenticate_user method. Besides that, the name of the method makes it sound like that will happen.

Instagram.set('client_secret', config.client_secret);
module.exports = (robot) ->
robot.respond /(insta tag)( me )?(.*)/i, (msg) ->
count = 1
authenticate_user()
if msg.match[3]
text = msg.match[3].trim()
text = text.split(" ")
tag = text[0]
count = text[1] if text[1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would come back as a string, so you'll need to parseInt it

else
msg.send 'Please provied tag'
return
Instagram.tags.recent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this API have an option for limiting results? It may be easier to do that, and show all images, rather than doing a while loop below.

name: "#{tag}"
complete: (data) ->
index = 1
while index <= count
msg.send data[index]['images']['standard_resolution']['url']
index++

authenticate_user = () ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idiomatic coffeescript would be camel case, ie authenticateUser.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and remove the (), they're not needed for no params, also they look unsightly :)

unless config.client_key
msg.send "Please set the HUBOT_INSTAGRAM_CLIENT_KEY environment variable."
return
unless config.client_secret
msg.send "Please set the HUBOT_TWITTER_ACCESS_TOKEN environment variable."
return