Monitoring and reminder of yuanyou blog using fetion API and RSS

Source: Internet
Author: User

I haven't written it for a long timeCodeThe recent work and code have almost no contact. They are all manual operations: Installing the system, installing software, reading log files, and repeating the steps. I just found some interesting APIs to make a small one.ProgramShare with you and train your trainer.

 

Main functions:

The program is very small. The main function is to monitor the blog site (the RSS content is consistent with the blog site ).ArticleThen, send a text message to remind you. First, paste a picture to give you a general understanding:

 

 

(Because I am an English system, I cannot enter Chinese Characters in Windows paint)

 

Technology involved:

1. XML parsing. The implementation here is relatively simple. Adding XPath to the xmldocument built in. Net meets the requirements.

2. I think the best solution is to send text messages to mobile phones for free. However, the official API of Feixin is not published, and the API on the sms.yicker.com website is quite convenient to use.

Note that the sms api of sms.yicker.com is a GET request.Https://sms.yicker.com/api/Mobile phone number/Feixin password/sending information, If the sent information contains Chinese characters, it should be htmlencode.

 

Implementation:

First, start with the monitoring method. This method is mainly used to get the article and send a text message reminder. The Code is as follows:

 

Code

     Public     Static     Void  Monitor ()
{
// Obtain the RSS file of a blog, which is generally in XML format.
String XML = Httpget (blogrssurl );
// Parse and retrieve all Article nodes
Xmlnodelist articles = Getarticles (XML );

Foreach (Xmlnode article In Articles)
{
// Get the guid node of the article
Xmlnode guid = Article. selectsinglenode ( " // Item/GUID " );
// Notified articles
If (Isnotified (guid. innertext ))
{
Continue ;
}
// Articles not notified
Else
{
// Get article title Node
Xmlnode title = Article. selectsinglenode ( " // Item/Title " );
Inform (title. innertext );
}
}
}

 

 

The method for obtaining and sending text messages is as follows:

 

Code

  Public     Static  Xmlnodelist getarticles (  String  XML)
{
Xmldocument Doc = New Xmldocument ();
Doc. loadxml (XML );
Xmlnodelist articles = Doc. selectnodes ( " // Item " );
Return Articles;
}

Public Static Void Inform ( String Message)
{
// Encode the information to be sent because it has Chinese characters.
Message = Httputility. htmlencode (Message );
String URL = String . Format ( " {0}/{1}/{2}/{3} " , Fetionapiurl, mobileno, password, message );
Httpget (URL );
}

 

 

All HTTP requests here only require the get method. The specific code is not listed. I have packaged the code and can download it whenever necessary.

Program extension:

This program is small, but there are many points worth improving.

In terms of functions, SMS reminders can be used in many aspects, including website monitoring, email reminders, and microblogs .. Wait, as long as you have a flying signal, these can be done for free.

Technically, SMS reminders are recorded in a dictionary and can be stored in external files or databases. Currently, the program only monitors one blog. If you need to monitor Multiple blogs, you can use multiple threads for better experience. Of course there are others ..

In view of the limited energy, I have implemented so much. If you are interested, you can put the code down and extend and improve it. If you can make more interesting things, you can share them together.

 

Related information:

W3cschool XPath Tutorial: http://www.w3school.com.cn/xpath/

 

Code: Download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.