-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilterMovieFeed.html
102 lines (94 loc) · 3.21 KB
/
filterMovieFeed.html
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
<!doctype html>
<html><head>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript">
slack_url = "https://slack.com/api/chat.postMessage";
test_slack_params = {
"channel" : "#test",
"username" : "test",
"token" : "slack_token",
};
function process(lookup) {
url = "https://feed.com/api/v2/list_movies.json";
url_d = "https://feed.com/api/v2/movie_details.json";
//testing
test_slack_params.text = "filtering "+lookup
jQuery.getJSON(slack_url, test_slack_params, function(results) {});
jQuery.getJSON(url, {'query_term' : lookup}, function(results) {
movies = results.data.movies;
//testing
test_slack_params.text = "found "+movies.length+" movies"
jQuery.getJSON(slack_url, test_slack_params, function(results) {});
movies.forEach(function(movie) {
if (movie.title_long == getQueryVariable('title')) {
jQuery.getJSON(url_d, {'movie_id' : movie.id}, function(results_d) {
movie_d = results_d.data;
if (movie.year < 2000) {
//testing
test_slack_params.text = lookup+" with "+movie.year+" year < 2000"
jQuery.getJSON(slack_url, test_slack_params, function(results) {});
return false;
}
restrictedRating = ["R", "Unrated", "Not Rated", "18"];
if (restrictedRating.indexOf(movie.mpa_rating) != -1) {
//testing
test_slack_params.text = lookup+" with "+movie.mpa_rating+" rating has restricted Rating"
jQuery.getJSON(slack_url, test_slack_params, function(results) {});
return false;
}
genres = movie_d.genres.join(", ");
content = [movie.mpa_rating, genres, "http://www.imdb.com/title/"+movie.imdb_code, movie_d.description_full].join("\n");
sendNotification(content);
})
//testing
} else {
test_slack_params.text = movie.title_long+" doesn't equal "+getQueryVariable('title')
jQuery.getJSON(slack_url, test_slack_params, function(results) {});
}
})
})
}
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return decodeURIComponent(pair[1]);}
}
return(false);
}
function sendNotification(content) {
title = getQueryVariable('title');
image = getQueryVariable('image');
attachments = [
{
"title" : title,
"title_link" : "http://my-server.com/movieDownloader/?lookup="+lookup,
"thumb_url" : image,
"text" : content,
"mrkdwn_in" : ["text"],
"fallback" : title,
}
];
attachments_json = JSON.stringify(attachments);
params = {
"channel" : "#movies",
"username" : "movie-bot",
"token" : "slack_token",
"attachments" : attachments_json,
};
url = "https://slack.com/api/chat.postMessage";
jQuery.getJSON(url, params, function(results) {});
}
lookup = getQueryVariable('title')
//testing
test_slack_params.text = "Title is "+lookup
jQuery.getJSON(slack_url, test_slack_params, function(results) {});
lookup = lookup.split(" (");
lookup = lookup[0];
lookup = lookup.trim().replace(/[^\d\w\'\.\-\/&@ _]+/, '');
process(lookup);
</script>
</head></html>