Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Xml
- Imports System.Web
- Public Class Form1
- Private Structure struct_Tweet
- Public guid As String
- Public Title As String
- Public link As String
- Public description As String
- Public pubDate As String
- Public enclosure As String
- Public category As String
- End Structure
- Private Tweets As List(Of struct_Tweet)
- Private mUrl_Search As String = "http://www.queryfeed.net/twitter?q="
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Tweets = New List(Of struct_Tweet)
- 'Process("shadowtzu")
- Process("#gamedev")
- '100 is maximum
- If Tweets.Count > 0 Then
- MsgBox("Result Count: " & Tweets.Count & vbCrLf _
- & "Last Tweet: " & vbCrLf _
- & "User: " & Tweets(0).Title & vbCrLf _
- & "Date: " & Tweets(0).pubDate & vbCrLf _
- & "Text: " & Tweets(0).description)
- End If
- End Sub
- Private Sub Process(Search As String)
- 'Dim SDate As DateTime = Date.Now.AddDays(-1)
- ' Dim Since As String = "since:" & SDate.Year & "-" & SDate.Month & "-" & SDate.Day
- Dim doc As New XmlDocument()
- Dim HasError As Boolean = False
- Do
- Try
- doc.Load(Url_Search(Search)) ' & " " & Since
- HasError = False
- Catch ex As Exception
- HasError = True
- End Try
- Loop While HasError = True
- For Each MainNode As XmlNode In doc.ChildNodes
- For Each rss As XmlNode In MainNode
- If rss.Name = "channel" AndAlso rss.HasChildNodes Then
- For Each Child As XmlNode In rss.ChildNodes
- If Child.Name = "item" AndAlso Child.HasChildNodes Then
- Dim NewTweet As struct_Tweet = Nothing
- With NewTweet
- If Not Child("guid") Is Nothing Then .guid = Child("guid").InnerText
- If Not Child("title") Is Nothing Then .Title = Child("title").InnerText
- If Not Child("link") Is Nothing Then .link = Child("link").InnerText
- If Not Child("description") Is Nothing Then .description = Child("description").InnerText
- If Not Child("pubDate") Is Nothing Then .pubDate = Child("pubDate").InnerText
- If Not Child("enclosure") Is Nothing Then .enclosure = ReadTag(Child("enclosure"), "url")
- If Not Child("category") Is Nothing Then .category = Child("category").InnerText
- End With
- Tweets.Add(NewTweet)
- End If
- Next
- End If
- Next
- Next
- End Sub
- Private Function Url_Search(Search As String) As String
- Return mUrl_Search & URLEncode(Search) & "&geocode="
- End Function
- Private Function ReadTag(Node As XmlNode, Tag As String, Optional DefaultValue As String = "") As String
- If Not Node.Attributes Is Nothing Then
- If Not Node.Attributes(Tag) Is Nothing Then
- Return Node.Attributes(Tag).Value
- Else
- Return DefaultValue
- End If
- Else
- Return DefaultValue
- End If
- End Function
- Public Function URLEncode(StringToEncode As String) As String
- Return HttpUtility.UrlEncode(StringToEncode)
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement