Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit870a21b

Browse files
committed
rsdn topic loader. parsing html;
1 parent062347b commit870a21b

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

‎NemerleWeb.Rsdn.Tree/MVVM/TopicList.n‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ namespace Rsdn
1818
publicclass TopicList
1919
{
2020
[Dto]publicclass Topic { Name :string; Author :string; Rating :string; Comments :string; Url :string }
21+
[Dto]publicclass CommentNode { Text :string; Children : List[CommentNode] }
2122

2223
privatemutable _url :string;
2324
privatemutable _topics : List[Topic];
25+
privatemutable _selectedTopic : CommentNode;
2426

2527
public Url :string
2628
{
@@ -33,14 +35,14 @@ namespace Rsdn
3335

3436
OpenTopic(url :string) :void
3537
{
36-
window.alert(url);
38+
_ = server.LoadReplies(url, node => _selectedTopic = node);
3739
}
3840

3941
[Html]
4042
public View() :string
4143
{
4244
<#
43-
<div $foreach(topicin _topics)class="topic" click="$(OpenTopic(topic.Url))">
45+
<div $foreach(topicin _topics)class="topic" click="$(OpenTopic(topic.Url))" visible="$(_selectedTopic == null)">
4446
<spanclass="topic-name">$(topic.Name)</span>
4547
<spanclass="topic-comment-count">Ответов: $(topic.Comments)</span>
4648
<spanclass="topic-author">Автор: $(topic.Author)</span>
@@ -55,6 +57,11 @@ namespace Rsdn
5557
{
5658
TopicLoader.GetTopicList(url);
5759
}
60+
61+
public LoadReplies(url :string) : CommentNode
62+
{
63+
TopicLoader.LoadReplies(url)
64+
}
5865
}
5966
}
6067
}

‎NemerleWeb.Rsdn.Tree/Models/TopicLoader.n‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
using Nemerle.Collections;
33
using Nemerle.Text;
44
using Nemerle.Utility;
5+
using Nemerle.Imperative;
56

67
using System;
78
using System.Collections.Generic;
89
using System.Linq;
10+
using System.Net;
11+
using System.Text.RegularExpressions;
912

1013
using HtmlAgilityPack;
1114

@@ -31,5 +34,36 @@ namespace Rsdn.Tree.Models
3134
TopicList.Topic(name, author, rating, comments, url);
3235
});
3336
}
37+
38+
public LoadReplies(url :string) : TopicList.CommentNode
39+
{
40+
def start = url.LastIndexOf('/');
41+
def end = url.LastIndexOf('.');
42+
43+
when (start ==-1 || end ==-1)
44+
return TopicList.CommentNode();
45+
46+
def id = url.Substring(start+1, (end- start)-1);
47+
def replies = WebClient().DownloadString("http://rsdn.ru/Forum/LoadRe.aspx?tid="+ id);
48+
49+
def start' = replies.IndexOf("window.parent.LE");
50+
def start'' = replies.IndexOf("\"", start');
51+
def end' = replies.IndexOf('\n', start'') - 3;
52+
def repliesHtml = replies.Substring(start'', end'- start'');
53+
54+
def doc = HtmlDocument();
55+
doc.LoadHtml(repliesHtml);
56+
def docNode = doc.DocumentNode;
57+
58+
def buildCommentNode(node, isRoot) {
59+
def url =if(!isRoot) node.SelectSingleNode(".//a[@href]").Attributes["href"].Valueelse"";
60+
TopicList.CommentNode(url, node.ChildNodes
61+
.Where(c => c.Name =="table")
62+
.Select(c => buildCommentNode(c, false)).ToList())
63+
}
64+
65+
def res = buildCommentNode(docNode, true);
66+
res
67+
}
3468
}
3569
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp