duangsuse::Echo
那么,完成这程序需要的一些信息: #Kotlin #tools #project — Regex 正则表达式匹配 group 新消息的 Regex /^(.+), \[(\d{2})\.(\d{2})\.(\d{2}) (\d{2}):(\d{2})\]$/ 对应数据:data class MessageHead(val channel: DisplayName, val date: Date) 新消息,reply to /^\[In reply to (.+)\]$/ 数据:data class R…
刚才写了一点实际非数据的代码,考虑了一下『InputStream 缓冲』的问题,以及啥是缓冲,没有难住我,太好了 🐱
duangsuse::Echo
🤔 想想 Scanner 是不是不够优雅...
我觉得就 Scanner 的逻辑结构上应该不够优雅,state 几乎是个笑话、lineDoUntil 非得加一个『keepLastLineOnce』才能用(doUntil 是在 scan body 里看到 new message header 的时候用的,可是等到这个 Message 返回,新 message 头会被下一次 iteration 直接忽视掉(因为我没设计好数据流,然后每次由判断 hasNext 的函数读新行的),导致漏掉偶数消息,不得不引入类似『mark/reset』的机制才可以),不过能用就好(跑路 🙈
duangsuse::Echo
telegramscanner.zip
最后写下 XML 序列化就彻底完成了!(因为这个最终是要用 Ruby 来查询数据的,虽然我有写 JavaFX GUI 的打算,可是我觉得还是晚一点好。
🤔 这是写 HTML 的节奏?虽然是 XML... 跑,反正都是 SGML 呢?(
telegram-scanner.jar
34.2 KB
Maven jar plugin 生成的 Jar application,可选 -test, -dump, -dump-yaml, -dump-debug-yaml
duangsuse::Echo
Photo
在 Ruby 里,要把它解析成 List & Object 的形式,只需要利用 Nokogiri:require 'nokogiri'
plain = File.read('test.xml')
doc = Nokogiri.parse(plain)
root = doc.children[0]
def collect_real_tags(xml)
i = 1; ret = []
while i < xml.size
ret << xml[i]
i += 2
end
return ret
end
real = collect_real_tags root.children
m = real.map { |n| n.children.find_all { |i| i.is_a? Nokogiri::XML::Element } }
m.map! { |a| a.find_all { |i| i.name == "dt" }.zip(a.find_all { |i| i.name == "dd" }).map { |n| [n.first.children[0].text, n.last.children.text] } }
m.map!(&:to_h)
r = m.dup最后再 post-process 一下就可以了
r.map! { |h| h.merge({'debug' => %w[no off line message_line].zip(h['debug'].match(/\{message_no=(\d+),\s*offset=(\d+),\s*line=(\d+),\s*message_line=(\d+)\}/).captures.map(&:to_i)).to_h, 'hashtags' => h['hashtags'].tr("[]", "").split(','), 'links' => h['links'].tr("[] ", "").split(',') }) }
# time
r.map! { |h| h.merge({ 'published' => Time.at(0, h['published'].to_i, :millisecond) }) }
duangsuse::Echo
在 Ruby 里,要把它解析成 List & Object 的形式,只需要利用 Nokogiri: require 'nokogiri' plain = File.read('test.xml') doc = Nokogiri.parse(plain) root = doc.children[0] def collect_real_tags(xml) i = 1; ret = [] while i < xml.size ret << xml[i] i += 2 end …
This media is not supported in your browser
VIEW IN TELEGRAM
🤔 下面就是本 #Telegram Channel 的消息内容统计信息了