init commit

This commit is contained in:
Tommy Parnell
2015-03-19 00:01:29 -04:00
parent 89a4be8f6b
commit 7e2bad34b4
88 changed files with 50091 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CsQuery;
using UntappedWidgetGenerator.Model;
namespace UntappedWidgetGenerator
{
public class UntappedRepository
{
public WidgetViewModel Get(string username)
{
if (String.IsNullOrWhiteSpace(username))
{
throw new ArgumentNullException("username");
}
var userProfile = String.Format("https://untappd.com/user/{0}", username);
var badgeProfile = String.Format("https://untappd.com/user/{0}/badges", username);
var dom = CQ.CreateFromUrl(userProfile);
var badgedom = CQ.CreateFromUrl(badgeProfile);
var badges = new List<Badge>();
badgedom[".badges .item a[href!=#]"].Each(a =>
{
badges.Add(new Badge()
{
LinkUrl = "https://untappd.com" + a.GetAttribute("href"),
ImageUrl = a.Cq().Find("img").Attr("data-original"),
Title = a.Cq().Find(".name").Text()
});
});
return new WidgetViewModel()
{
AvatarUrl = dom[".avatar-holder img"].Attr("src"),
//todo: Actually use regex this is terrible
HeaderBackgroundUrl =
dom[".profile_header"].Css("background-image").ToLower().TrimStart("url".ToCharArray()).TrimStart('(').TrimEnd(')').Trim('\''),
Info = dom[".info h1"].Text(),
Username = dom[".username"].Text(),
Badges = badges
};
}
}
}