Commit e5a6ef861e06fae536677e78e7b4cedf4dbdc342

Authored by James McMinn
1 parent cd59306788
Exists in master

Readme change

Showing 1 changed file with 2 additions and 1 deletions Inline Diff

1 Go Twitter Tools 1 Go Twitter Tools
2 ===================== 2 =====================
3 3
4 The Twitter Microblog Track runs a rather special Evaluation as a service 4 The Twitter Microblog Track runs a rather special Evaluation as a service
5 model, which allows participants to connect to a server to perform queries 5 model, which allows participants to connect to a server to perform queries
6 using a thrift-based API. This package provides a set of Go bindings for 6 using a thrift-based API. This package provides a set of Go bindings for
7 performing queries to the service, in addition to a wrapper library which 7 performing queries to the service, in addition to a wrapper library which
8 simplifies its use. 8 simplifies its use.
9 9
10 ## Requirements 10 ## Requirements
11 The library requires the thrift package from Apache, which can be installed 11 The library requires the thrift package from Apache, which can be installed
12 using: 12 using:
13 13
14 go get git.apache.org/thrift.git/lib/go/thrift 14 go get git.apache.org/thrift.git/lib/go/thrift
15 15
16 ## Installing 16 ## Installing
17 Go get can handle installation for you. 17 Go get can handle installation for you.
18 18
19 go get git.apache.org/thrift.git/lib/go/thrift 19 go get git.apache.org/thrift.git/lib/go/thrift
20 20
21 ## Usage 21 ## Usage
22 The library is modelled loosely on the official Microblog track client, which is written in Java. It’s very simple and implements 3 basic actions: 22 The library is modelled loosely on the official Microblog track client, which is written in Java. It’s very simple and implements 3 basic actions:
23 1. Create a connection 23 1. Create a connection
24 2. Perform a query and return results 24 2. Perform a query and return results
25 3. Close the connection. 25 3. Close the connection.
26
26 All of these are demonstrated in the example below. 27 All of these are demonstrated in the example below.
27 28
28 package main 29 package main
29 30
30 import ( 31 import (
31 "fmt" 32 "fmt"
32 "log" 33 "log"
33 "mirgit.dcs.gla.ac.uk/JamesMcMinn/twitter-tools-go" 34 "mirgit.dcs.gla.ac.uk/JamesMcMinn/twitter-tools-go"
34 ) 35 )
35 36
36 func main() { 37 func main() {
37 // Create a new client using the settings in conf.json 38 // Create a new client using the settings in conf.json
38 client, err := twittertools.NewClientFromConf("conf.json") 39 client, err := twittertools.NewClientFromConf("conf.json")
39 if err != nil { 40 if err != nil {
40 log.Fatal(err) 41 log.Fatal(err)
41 } 42 }
42 defer client.Close() 43 defer client.Close()
43 44
44 // query the server for "glasgow", retreive the top 50 results 45 // query the server for "glasgow", retreive the top 50 results
45 // -1 signifies that there is no maximum tweet ID 46 // -1 signifies that there is no maximum tweet ID
46 results, err := client.Search("Glasgow", 50, -1) 47 results, err := client.Search("Glasgow", 50, -1)
47 if err != nil { 48 if err != nil {
48 log.Fatal(err) 49 log.Fatal(err)
49 } 50 }
50 51
51 // Iterate over the results, printing text from each tweet 52 // Iterate over the results, printing text from each tweet
52 for k, result := range results { 53 for k, result := range results {
53 fmt.Println(k, result.Text) 54 fmt.Println(k, result.Text)
54 } 55 }
55 } 56 }
56 57
57 The example uses a conf.json file (example below) to load the server details and your team details. If you’d rather hard-code the values, the `twittertools.NewClientFromDetails(host, port, group, token)` function allows you to create a new client and specify the details manually. 58 The example uses a conf.json file (example below) to load the server details and your team details. If you’d rather hard-code the values, the `twittertools.NewClientFromDetails(host, port, group, token)` function allows you to create a new client and specify the details manually.
58 59
59 { 60 {
60 "Host": "server.address.edu", 61 "Host": "server.address.edu",
61 "Port": 9091, 62 "Port": 9091,
62 "Group": "UrTeamName", 63 "Group": "UrTeamName",
63 "Token": "de4db33f" 64 "Token": "de4db33f"
64 } 65 }