golang dump of versions

This commit is contained in:
Jeff Carr 2023-03-25 07:16:08 -05:00
parent bd2f756a8c
commit 4b9be3d24f
3 changed files with 156 additions and 0 deletions

12
gowikipedia/Makefile Normal file
View File

@ -0,0 +1,12 @@
# lists the changes to the Zinc page:
Zinc:
reset
go run zinc.go
# - ID: 824303964, Parent ID: 824303909, User: 204.122.110.237, UserID: 0, Timestamp: 2018-02-06T15:26:48Z, Comment: /* Physical properties */
# - ID: 824303909, Parent ID: 824303854, User: CLCStudent, UserID: 0, Timestamp: 2018-02-06T15:26:21Z, Comment: Reverted 1 edit by [[Special:Contributions/204.122.110.237|204.122.110.237]] ([[User talk:204.122.110.237|talk]]) to last revision by Onel5969. ([[WP:TW|TW]])
# - ID: 824303854, Parent ID: 824287944, User: 204.122.110.237, UserID: 0, Timestamp: 2018-02-06T15:26:01Z, Comment: /* Zinc(II) compounds */
# - ID: 824287944, Parent ID: 821850427, User: Onel5969, UserID: 0, Timestamp: 2018-02-06T13:21:44Z, Comment: Disambiguating links to [[Poppy]] (link changed to [[Poppy (flower)]]) using [[User:Qwertyytrewqqwerty/DisamAssist|DisamAssist]].
version:
go run getVersion.go

68
gowikipedia/getVersion.go Normal file
View File

@ -0,0 +1,68 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
const wikipediaAPI = "https://en.wikipedia.org/w/api.php"
type QueryResponse struct {
Batchcomplete string `json:"batchcomplete"`
Query struct {
Pages map[string]struct {
Pageid int `json:"pageid"`
Ns int `json:"ns"`
Title string `json:"title"`
Content string `json:"content"`
} `json:"pages"`
} `json:"query"`
}
// - ID: 824303964, Parent ID: 824303909, User: 204.122.110.237, UserID: 0, Timestamp: 2018-02-06T15:26:48Z, Comment: /* Physical properties */
// - ID: 824303909, Parent ID: 824303854, User: CLCStudent, UserID: 0, Timestamp: 2018-02-06T15:26:21Z, Comment: Reverted 1 edit by [[Special:Contributions/204.122.110.237|204.122.110.237]] ([[User talk:204.122.110.237|talk]]) to last revision by Onel5969. ([[WP:TW|TW]])
// - ID: 824303854, Parent ID: 824287944, User: 204.122.110.237, UserID: 0, Timestamp: 2018-02-06T15:26:01Z, Comment: /* Zinc(II) compounds */
// - ID: 824287944, Parent ID: 821850427, User: Onel5969, UserID: 0, Timestamp: 2018-02-06T13:21:44Z, Comment: Disambiguating links to [[Poppy]] (link changed to [[Poppy (flower)]]) using [[User:Qwertyytrewqqwerty/DisamAssist|DisamAssist]].
func main() {
params := url.Values{}
params.Set("action", "query")
params.Set("format", "json")
params.Set("prop", "revisions")
params.Set("titles", "Zinc")
params.Set("rvprop", "content")
params.Set("rvslots", "main")
params.Set("rvlimit", "1")
params.Set("revids", "824287944")
url := fmt.Sprintf("%s?%s", wikipediaAPI, params.Encode())
resp, err := http.Get(url)
if err != nil {
fmt.Printf("Error making request: %v\n", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Error reading response: %v\n", err)
return
}
var queryResponse QueryResponse
err = json.Unmarshal(body, &queryResponse)
if err != nil {
fmt.Printf("Error unmarshalling JSON: %v\n", err)
return
}
for _, page := range queryResponse.Query.Pages {
fmt.Printf("Content for '%s' (revision ID: 825282998):\n\n", page.Title)
fmt.Println(page.Content)
}
}

76
gowikipedia/zinc.go Normal file
View File

@ -0,0 +1,76 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
const wikipediaAPI = "https://en.wikipedia.org/w/api.php"
type QueryResponse struct {
Batchcomplete string `json:"batchcomplete"`
Continue struct {
RvContinue string `json:"rvcontinue"`
Continue string `json:"continue"`
} `json:"continue"`
Query struct {
Pages map[string]struct {
Pageid int `json:"pageid"`
Ns int `json:"ns"`
Title string `json:"title"`
Revisions []Revision `json:"revisions"`
} `json:"pages"`
} `json:"query"`
}
type Revision struct {
Revid int `json:"revid"`
Parentid int `json:"parentid"`
User string `json:"user"`
Userid int `json:"userid"`
Timestamp string `json:"timestamp"`
Comment string `json:"comment"`
}
func main() {
params := url.Values{}
params.Set("action", "query")
params.Set("format", "json")
params.Set("prop", "revisions")
params.Set("titles", "Zinc")
params.Set("rvlimit", "max")
params.Set("rvprop", "timestamp|user|comment|ids")
url := fmt.Sprintf("%s?%s", wikipediaAPI, params.Encode())
resp, err := http.Get(url)
if err != nil {
fmt.Printf("Error making request: %v\n", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Error reading response: %v\n", err)
return
}
var queryResponse QueryResponse
err = json.Unmarshal(body, &queryResponse)
if err != nil {
fmt.Printf("Error unmarshalling JSON: %v\n", err)
return
}
for _, page := range queryResponse.Query.Pages {
fmt.Printf("Revisions for '%s':\n", page.Title)
for _, revision := range page.Revisions {
fmt.Printf("- ID: %d, Parent ID: %d, User: %s, UserID: %d, Timestamp: %s, Comment: %s\n",
revision.Revid, revision.Parentid, revision.User, revision.Userid, revision.Timestamp, revision.Comment)
}
}
}