Created
June 26, 2010 15:58
-
-
Save troygoode/454149 to your computer and use it in GitHub Desktop.
Refactoring of code in Scott Hanselman's post: http://www.hanselman.com/blog/TheWeeklySourceCode53GeterDoneEditionXMLInTheLeftHandBecomesHTTPPOSTsInTheRightHand.aspx
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
using System; | |
using System.Linq; | |
using System.IO; | |
using System.Xml.Linq; | |
using System.Threading; | |
namespace TumblrAPI.ConsoleApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Started..."); | |
TumblrAPI.Authentication.Email = "[email protected]"; //Console.ReadLine(); | |
TumblrAPI.Authentication.Password = "poopypants"; //Console.ReadLine(); | |
if(TumblrAPI.Authenticaiton.Status != TumblrAPI.AuthenticationStatus.Valid) | |
throw new UnauthorizedAccessException("Incorrect Tumblr credentials."); | |
Console.WriteLine("Now make some posts..."); | |
//Get the DasBlog XML files, they are like <entry><title/><content/></entry> and stuff | |
XNamespace ns = "urn:newtelligence-com:dasblog:runtime:data"; | |
var posts = | |
from file in DirectoryInfo(@"C:\overheardathome\xml").GetFileSystemInfos("*.dayentry.xml") | |
orderby file.Name | |
from entry in XDocument.Load(file.FullName).Root.Descendants(ns + "Entry") | |
select new TumblrAPI.Post.Text{ | |
Title = (string)entry.Element(ns + "Title"), | |
Body = (string)entry.Element(ns + "Content") | |
}; | |
foreach(var post in posts){ | |
Console.WriteLine(" Response from text post: {0}", post.Publish()); | |
Thread.Sleep(500); //Tumblr will API limit me if I bash on them. | |
} | |
Console.WriteLine("Done, press any key..."); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment