Skip to content

Instantly share code, notes, and snippets.

@skymonsters-Ks
Last active November 2, 2019 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skymonsters-Ks/695bf2fb35bd7074413651e96fcf49bd to your computer and use it in GitHub Desktop.
Save skymonsters-Ks/695bf2fb35bd7074413651e96fcf49bd to your computer and use it in GitHub Desktop.
HSPプログラムコンテストの作品をリスト&カウント
; Enterキーで選択中の作品ページを開きます
#include "hspinet.as"
#define URL_BASE "dev.onionsoft.net/seed/info.ax?id="
#define PROTOCOL "https://"
netinit
if stat : dialog "connection error" : end
; 年度
year = "2019" ; 2012年より前は非対応
; 部門
category = "n", "s", "d"
cate_name = "一般", "HSPTV", "Dish"
sdim listBuf, 32000
neturl PROTOCOL + "hsp.tv/contest" + year + "/"
num_str = "("
num_total = 0
foreach category : cate_id = cnt
num_cate(cate_id) = 0
repeat , 1
fn = "list_" + category(cate_id) + cnt + ".html"
request fn
if stat : break
title "downloading " + fn
gosub *downloadLoop
gosub *getWork
loop
num_str += strf("%s:%d, ", cate_name(cate_id), num_cate(cate_id))
loop
poke num_str, strlen(num_str) - 2
title strf("作品数:%d %s)", num_total, num_str)
objsize 640, 480
listbox listid, 0, listBuf
notesel listBuf
onkey gosub *inKey
onexit goto *save
stop
*inKey
if lparam >> 30 : return
if wparam == 13 { ; Enter
noteget ts, listid
getstr id, ts, 1, ':'
exec PROTOCOL + URL_BASE + int(id), 16
}
return
*save
dialog "リストを保存しますか?", 2
if stat == 6 {
dialog "txt", 17
if stat : notesave refstr
}
end
end
#deffunc request str _fn
netfileinfo info, _fn
if stat {
dialog "info error"
end
}
getstr ts, info
if instr(ts, 0, "404") >= 0 {
return 1
}
netrequest_get _fn
return 0
*downloadLoop
netexec res
if res < 0 {
neterror estr
dialog "download error: " + estr
end
}
if res > 0 {
netgetv buf
return
}
await 50
goto *downloadLoop
*getWork
pt = instr(buf, 0, "<!--段落始まり-->")
repeat
t = instr(buf, pt, "<a name=")
if (t < 0) : break
pt += t
getstr id, buf, pt + 9, '\"'
url = URL_BASE + id
pt += instr(buf, pt, url)
getstr name, buf, pt + strlen(url) + 2, '<'
listBuf += strf("#%05d: %s\n", id, name)
num_total++
num_cate(cate_id)++
loop
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment