Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mono-rss.cs « web « doc - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a4fdd49c365931d161e6b92b44dd348dae380e32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// Generates the Mono RSS feed
//
// Miguel de Icaza
//
using System;
using System.IO;
using System.Xml;
using RSS;

class X {
	static RSS.RSS rss;
	static Channel c;
	static int item_count;

	static void PopulateRSS (StreamReader input)
	{
		string s;
		
		while ((s = input.ReadLine ()) != null){
			if (s.StartsWith ("@item "))
				break;
		}

		if (s == null || !s.StartsWith ("@item ")){
			Console.WriteLine ("Could not find beginning of text to RSS");
			return;
		}

		Item i = null;
		string description = "";
		do {
			if (s.StartsWith ("@item ")){
				if (item_count++ > 25)
					break;

				if (i != null){
					i.Description = description;
					description = "";
				}
				
				string title = s.Substring (6);
				string link = "http://www.go-mono.com/index.html#";
				foreach (char ch in title){
					if (ch != ' ')
						link += ch;
				}
				
				i = c.NewItem ();
				i.Title = title;
				i.Link = link;
			} else {
				description += "\n" + (s == "\n" ? "<p>" : s);
			}
		} while ((s = input.ReadLine ()) != null);

		if (i != null){
			i.Description = description;
		}
	}
	
	static void MakeRSS (string input, string output)
	{
		rss = new RSS.RSS ();
		c = rss.NewChannel ("Mono Project News", "http://www.go-mono.com");
		
		c.Title = "Mono Project News";
		c.Link = "http://www.go-mono.com";
		c.Description =
		"News from the Mono project: a portable implementation of the .NET Framework";
		c.WebMaster = "webmaster@go-mono.com";
		c.ManagingEditor = "miguel@ximian.com";
		string t = File.GetLastWriteTime (input).ToString ("r");
		c.PubDate = t;
		c.LastBuildDate = t;

		using (FileStream fs = new FileStream (input, FileMode.Open)){
			using (StreamReader input_stream = new StreamReader (fs)){
				PopulateRSS (input_stream);
			}
		}
		
		rss.XmlDocument.Save (output);
	}
	
	static int Main (string [] args)
	{
		switch (args.Length){
		case 0:
			MakeRSS ("index", "index.rss");
			break;
		case 2:
			MakeRSS (args [0], args [1]);
			break;
			
		default:
			Console.WriteLine ("Usage is: mono-rss [input output.rss]");
			return 1;
		}

		return 0;
	}
}