Created
November 23, 2015 09:17
-
-
Save abergs/d132488d67b50f3fbc34 to your computer and use it in GitHub Desktop.
Feedrepublic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
google.load("visualization", "1", {packages:["corechart"]}); | |
google.setOnLoadCallback(drawChart); | |
function drawChart() { | |
$.getJSON( "http://feedrepublic.azurewebsites.net/api/popular-filters-global/", function( data ) { | |
// put data into the graph | |
data= data.slice(0,5); | |
data.unshift(["filter","number"]); | |
var dataTable = google.visualization.arrayToDataTable(data); | |
var options = { | |
title: 'Most common filter Worldwide', | |
pieHole: 0.4, | |
}; | |
var chart = new google.visualization.PieChart(document.getElementById('donutchart')); | |
chart.draw(dataTable, options); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add this code to the auth object | |
var auth = new OAuth(config); | |
// now we have to call back to instagram and include the code they gave us | |
// along with our client secret | |
var oauthResponse = await auth.RequestToken(code); | |
var worker = new Worker(); | |
var jobId = BackgroundJob.Enqueue(() => worker.ImportFollowings(oauthResponse)); | |
BackgroundJob.ContinueWith(jobId, () => worker.DoStuff(oauthResponse, 0, null)); | |
//await Downloader.GetFeed(oauthResponse); | |
// both the client secret and the token are considered sensitive data, so we won't be | |
// sending them back to the browser. we'll only store them temporarily. If a user's session times | |
// out, they will have to click on the authenticate button again - sorry bout yer luck. | |
Session.Add("InstaSharp.AuthInfo", oauthResponse); | |
// all done, lets redirect to the home controller which will send some intial data to the app | |
return Redirect("http://abergs.github.io/feedRepublic/frontend/user.html?user=" + oauthResponse.User.Username); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet] | |
[Route("~/api/popular-filters-global")] | |
public IEnumerable<dynamic> PopularFiltersGlobal() | |
{ | |
using (var db = GetOpenConnection()) | |
{ | |
var q = @" | |
SELECT COUNT(filter) AS value, filter as Topic FROM images | |
WHERE [type]='image' | |
GROUP BY images.filter | |
ORDER BY value desc | |
"; | |
var res = db.Query<Result1>(q); | |
return res.Select(r => { return new dynamic[] { r.Topic, r.Value }; }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Queue("imagetagging")] | |
public void CategorizeImage(string id, string url) | |
{ | |
using (var db = GetOpenConnection()) | |
{ | |
var res = db.Query("SELECT Id FROM image_topic where imageId = @id", new { id }); | |
if (res.Count() > 0) return; | |
Com.Imagga.Api.Imagga.ApiInvoker.username = "KINDA_SECRET"; | |
Com.Imagga.Api.Imagga.ApiInvoker.password = "SUPA SECRET"; | |
var api = new Com.Imagga.Api.Imagga.Api.CategorizationsApi(); | |
var response = api.Categorize("personal_photos", url, null); | |
if (response.Unsuccessful != null) return; | |
foreach (var item in response.Results) | |
{ | |
foreach (var tag in item.Categories) | |
{ | |
db.Execute("insert into image_topic (imageId, topic, confidence) VALUES (@id, @topic, @confidence)", | |
new { id = id, topic = tag.Name, confidence = tag.Confidence }); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment