3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

mindの研究 その74

Last updated at Posted at 2024-03-05

概要

mindが、謎なので調べてみた。
練習問題やってみた。

練習問題

mindで、QiitaAPIを叩け。

方針

  • HttpGetは、Vbsの力を借りる。
  • Jsonパースも、Vbsの力を借りる。

サンプルコード


出力ファイルは ファイル。
メモ帳は ファイル。

メインとは
 行は 文字列
 「getjson.vbs」で 出力ファイルを 新規オープンし
 「Function GetJson(url)」で 出力ファイルに 一行書き込み
 「	Set sh = CreateObject("WScript.Shell")」で 出力ファイルに 一行書き込み
 「	cd = sh.CurrentDirectory」で 出力ファイルに 一行書き込み
 「	FileName = "json.txt"」で 出力ファイルに 一行書き込み
 「	SamAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"」で 出力ファイルに 一行書き込み
 「	hts = ""」で 出力ファイルに 一行書き込み
 「	Set objHTTP = CreateObject("Microsoft.XMLHTTP")」で 出力ファイルに 一行書き込み
 「	objHTTP.Open "GET", url, False」で 出力ファイルに 一行書き込み
 「	objHTTP.SetRequestHeader "User-Agent", SamAgent」で 出力ファイルに 一行書き込み
 「	objHTTP.Send」で 出力ファイルに 一行書き込み
 「	Set objStream = CreateObject("ADODB.Stream")」で 出力ファイルに 一行書き込み
 「	objStream.Type = 1」で 出力ファイルに 一行書き込み
 「	objStream.Open」で 出力ファイルに 一行書き込み
 「	objStream.Write objHTTP.responseBody」で 出力ファイルに 一行書き込み
 「	objStream.Position = 0」で 出力ファイルに 一行書き込み
 「	objStream.Type = 2」で 出力ファイルに 一行書き込み
 「	objStream.Charset = "UTF-8"」で 出力ファイルに 一行書き込み
 「	http_source = objStream.ReadText」で 出力ファイルに 一行書き込み
 「	objStream.Close」で 出力ファイルに 一行書き込み
 「	hts = http_source」で 出力ファイルに 一行書き込み
 「	Set sc = CreateObject("MSScriptControl.ScriptControl")」で 出力ファイルに 一行書き込み
 「	sc.Language = "JavaScript"」で 出力ファイルに 一行書き込み
 「	sc.AddCode "var csv = '';"」で 出力ファイルに 一行書き込み
 「	sc.AddCode "var res = " && hts && ";"」で 出力ファイルに 一行書き込み
 「	s = "for (var i = 0; i < res.length; i++){csv += res[i].created_at + ' ';res[i].title = res[i].title.replace(/ /g, '-');"」で 出力ファイルに 一行書き込み
 「	v = "csv += res[i].title + ' ';csv += res[i].url + ' ';csv += res[i].id + ' ';csv += res[i].user.id + '\n';}"」で 出力ファイルに 一行書き込み
 「	sc.AddCode s && v」で 出力ファイルに 一行書き込み
 「	Set cf = sc.CodeObject」で 出力ファイルに 一行書き込み
 「	hts = cf.csv」で 出力ファイルに 一行書き込み
 「	Set fs = CreateObject("Scripting.FileSystemObject")」で 出力ファイルに 一行書き込み
 「	FileName = fs.BuildPath(cd, FileName)」で 出力ファイルに 一行書き込み
 「	Set file = fs.CreateTextFile(FileName, True)」で 出力ファイルに 一行書き込み
 「	file.Write(hts)」で 出力ファイルに 一行書き込み
 「	file.Close」で 出力ファイルに 一行書き込み
 「Set file = Nothing」で 出力ファイルに 一行書き込み
 「Set fs = Nothing」で 出力ファイルに 一行書き込み
 「Set objHTTP = Nothing」で 出力ファイルに 一行書き込み
 「Set objStream = Nothing」で 出力ファイルに 一行書き込み
 「End Function」で 出力ファイルに 一行書き込み
 「GetJson("https://qiita.com/api/v2/users/ohisama@github/items")」で 出力ファイルに 一行書き込み
 出力ファイルを クローズし
 「C:\Windows\SysWOW64\cscript getjson.vbs」を プログラム実行し
 「json.txt」で メモ帳を オープンし
 エラー?
 ならば
  エラー文字列で 重大エラーにし
 つぎに
 ここから
  メモ帳から 一行読み出し 行に 入れ
  データ終り?
  ならば
   打ち切り
  つぎに
  「行 = [」を 表示し 行を 表示し 「]」を 一行表示し
 繰り返し
 メモ帳を クローズする
。






実行結果

>getjson
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

行 = [2024-03-05T21:07:12+09:00 mindの研究-その73 https://qiita.com/ohisama@github/items/4a7e3c6acf18ebcc2550 4a7e3c6acf18ebcc2550 ohisama@github]
行 = [2024-03-05T11:17:05+09:00 cscの作法-その468 https://qiita.com/ohisama@github/items/28f2b027066e7c9db03b 28f2b027066e7c9db03b ohisama@github]
行 = [2024-03-05T09:00:05+09:00 cscの作法-その467 https://qiita.com/ohisama@github/items/0fa6f0941473f1c913a4 0fa6f0941473f1c913a4 ohisama@github]
行 = [2024-03-05T08:28:05+09:00 cscの作法-その466 https://qiita.com/ohisama@github/items/e03f63960d3ecd3208df e03f63960d3ecd3208df ohisama@github]
行 = [2024-03-05T08:19:21+09:00 cscの作法-その465 https://qiita.com/ohisama@github/items/d91075711cc96b347b8a d91075711cc96b347b8a ohisama@github]
行 = [2024-03-05T08:14:09+09:00 cscの作法-その464 https://qiita.com/ohisama@github/items/30ef94de4acf502313eb 30ef94de4acf502313eb ohisama@github]
行 = [2024-03-05T08:07:17+09:00 cscの作法-その463 https://qiita.com/ohisama@github/items/a397ccc7ef6fa388ae4a a397ccc7ef6fa388ae4a ohisama@github]
行 = [2024-03-04T16:54:57+09:00 wslでelixir-その141 https://qiita.com/ohisama@github/items/902a1dde7457c9392fbd 902a1dde7457c9392fbd ohisama@github]
行 = [2024-03-02T07:17:35+09:00 cscの作法-その462 https://qiita.com/ohisama@github/items/57cadf0b1629efb6cc98 57cadf0b1629efb6cc98 ohisama@github]
行 = [2024-03-02T06:24:49+09:00 cscの作法-その461 https://qiita.com/ohisama@github/items/2d0a56ece7769cd89b06 2d0a56ece7769cd89b06 ohisama@github]
行 = [2024-03-02T06:06:47+09:00 cscの作法-その460 https://qiita.com/ohisama@github/items/77b2253ae2e5e2fa6836 77b2253ae2e5e2fa6836 ohisama@github]
行 = [2024-02-28T07:52:05+09:00 cscの作法-その459 https://qiita.com/ohisama@github/items/41e84ad2b7a36c217c5a 41e84ad2b7a36c217c5a ohisama@github]
行 = [2024-02-26T04:32:35+09:00 PlunkerでPhaser.Physics-その15 https://qiita.com/ohisama@github/items/00e558a40781fbf684aa 00e558a40781fbf684aa ohisama@github]
行 = [2024-02-26T04:13:43+09:00 PlunkerでPhaser.Physics-その14 https://qiita.com/ohisama@github/items/35ffd56de70c195b109d 35ffd56de70c195b109d ohisama@github]
行 = [2024-02-25T10:45:34+09:00 PlunkerでPhaser.Physics-その13 https://qiita.com/ohisama@github/items/03ba871b4cfcb3ef2a6f 03ba871b4cfcb3ef2a6f ohisama@github]
行 = [2024-02-25T10:40:35+09:00 PlunkerでPhaser.Physics-その12 https://qiita.com/ohisama@github/items/24f20cc0ae0957ecdab1 24f20cc0ae0957ecdab1 ohisama@github]
行 = [2024-02-25T10:35:45+09:00 PlunkerでPhaser.Physics-その11 https://qiita.com/ohisama@github/items/f05827bf7cbb7c3c911c f05827bf7cbb7c3c911c ohisama@github]
行 = [2024-02-25T10:30:57+09:00 PlunkerでPhaser.Physics-その10 https://qiita.com/ohisama@github/items/426748032579118f4b4b 426748032579118f4b4b ohisama@github]
行 = [2024-02-25T10:25:21+09:00 PlunkerでPhaser.Physics-その9 https://qiita.com/ohisama@github/items/900c0fd857d534910bd5 900c0fd857d534910bd5 ohisama@github]
行 = [2024-02-24T11:02:09+09:00 PlunkerでPhaser.Physics-その8 https://qiita.com/ohisama@github/items/e937c0821323bf9abd86 e937c0821323bf9abd86 ohisama@github]

以上。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?