Skip to content

Commit 825b3e7

Browse files
committed
Add github.com/mmcdole/gofeed - Make guggy use DefaultService
1 parent c6a1580 commit 825b3e7

File tree

1,101 files changed

+292221
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,101 files changed

+292221
-16
lines changed

src/github.com/matrix-org/go-neb/goneb.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
_ "github.com/matrix-org/go-neb/realms/jira"
1111
"github.com/matrix-org/go-neb/server"
1212
_ "github.com/matrix-org/go-neb/services/echo"
13-
_ "github.com/matrix-org/go-neb/services/guggy"
1413
_ "github.com/matrix-org/go-neb/services/giphy"
1514
_ "github.com/matrix-org/go-neb/services/github"
15+
_ "github.com/matrix-org/go-neb/services/guggy"
1616
_ "github.com/matrix-org/go-neb/services/jira"
1717
"github.com/matrix-org/go-neb/types"
1818
_ "github.com/mattn/go-sqlite3"

src/github.com/matrix-org/go-neb/services/giphy/giphy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type giphyService struct {
3434
types.DefaultService
3535
id string
3636
serviceUserID string
37-
APIKey string `json:"api_key"`// beta key is dc6zaTOxFJmzC
37+
APIKey string `json:"api_key"` // beta key is dc6zaTOxFJmzC
3838
}
3939

4040
func (s *giphyService) ServiceUserID() string { return s.serviceUserID }

src/github.com/matrix-org/go-neb/services/guggy/guggy.go

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
11
package services
22

33
import (
4-
"encoding/json"
54
"bytes"
6-
"math"
5+
"encoding/json"
76
log "github.com/Sirupsen/logrus"
87
"github.com/matrix-org/go-neb/matrix"
98
"github.com/matrix-org/go-neb/plugin"
109
"github.com/matrix-org/go-neb/types"
10+
"math"
1111
"net/http"
1212
"strings"
1313
)
14+
1415
type guggyQuery struct {
1516
// "mp4" or "gif"
1617
Format string `json:"format"`
1718
// Query sentence
18-
Sentence string `json:"sentence"`
19+
Sentence string `json:"sentence"`
1920
}
2021

2122
type guggyGifResult struct {
22-
ReqID string `json:"reqId"`
23-
GIF string `json:"gif"`
24-
Width float64 `json:"width"`
23+
ReqID string `json:"reqId"`
24+
GIF string `json:"gif"`
25+
Width float64 `json:"width"`
2526
Height float64 `json:"height"`
2627
}
2728

2829
type guggyService struct {
30+
types.DefaultService
2931
id string
3032
serviceUserID string
31-
APIKey string `json:"api_key"`
33+
APIKey string `json:"api_key"`
3234
}
3335

3436
func (s *guggyService) ServiceUserID() string { return s.serviceUserID }
3537
func (s *guggyService) ServiceID() string { return s.id }
3638
func (s *guggyService) ServiceType() string { return "guggy" }
37-
func (s *guggyService) OnReceiveWebhook(w http.ResponseWriter, req *http.Request, cli *matrix.Client) {
38-
}
39-
func (s *guggyService) Register(oldService types.Service, client *matrix.Client) error { return nil }
40-
func (s *guggyService) PostRegister(oldService types.Service) {}
4139

4240
func (s *guggyService) Plugin(client *matrix.Client, roomID string) plugin.Plugin {
4341
return plugin.Plugin{
@@ -62,7 +60,7 @@ func (s *guggyService) cmdGuggy(client *matrix.Client, roomID, userID string, ar
6260
if gifResult.GIF == "" {
6361
return matrix.TextMessage{
6462
MsgType: "m.text.notice",
65-
Body: "No GIF found!",
63+
Body: "No GIF found!",
6664
}, nil
6765
}
6866

@@ -87,13 +85,13 @@ func (s *guggyService) cmdGuggy(client *matrix.Client, roomID, userID string, ar
8785
func (s *guggyService) text2gifGuggy(querySentence string) (*guggyGifResult, error) {
8886
log.Info("Transforming to GIF query ", querySentence)
8987

90-
client := &http.Client{ }
88+
client := &http.Client{}
9189

9290
var query guggyQuery
9391
query.Format = "gif"
9492
query.Sentence = querySentence
9593

96-
reqBody, err := json.Marshal(query);
94+
reqBody, err := json.Marshal(query)
9795
if err != nil {
9896
return nil, err
9997
}

vendor/manifest

+79
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
{
22
"version": 0,
33
"dependencies": [
4+
{
5+
"importpath": "github.com/PuerkitoBio/goquery",
6+
"repository": "https://github.com/PuerkitoBio/goquery",
7+
"revision": "152b1a2c8f5d0340f658bb656032a39b94e52958",
8+
"branch": "master"
9+
},
410
{
511
"importpath": "github.com/Sirupsen/logrus",
612
"repository": "https://github.com/Sirupsen/logrus",
713
"revision": "a283a10442df8dc09befd873fab202bf8a253d6a",
814
"branch": "master"
915
},
16+
{
17+
"importpath": "github.com/andybalholm/cascadia",
18+
"repository": "https://github.com/andybalholm/cascadia",
19+
"revision": "1c31af6f6c1a7b101ed05aacc7d8a738b43ae86e",
20+
"branch": "master"
21+
},
1022
{
1123
"importpath": "github.com/andygrunwald/go-jira",
1224
"repository": "https://github.com/andygrunwald/go-jira",
@@ -19,6 +31,12 @@
1931
"revision": "cdf48bbc1eb78d1349cbda326a4a037f7ba565c6",
2032
"branch": "master"
2133
},
34+
{
35+
"importpath": "github.com/codegangsta/cli",
36+
"repository": "https://github.com/codegangsta/cli",
37+
"revision": "d53eb991652b1d438abdd34ce4bfa3ef1539108e",
38+
"branch": "master"
39+
},
2240
{
2341
"importpath": "github.com/dghubble/go-twitter/twitter",
2442
"repository": "https://github.com/dghubble/go-twitter",
@@ -70,19 +88,80 @@
7088
"revision": "e118d4451349065b8e7ce0f0af32e033995363f8",
7189
"branch": "master"
7290
},
91+
{
92+
"importpath": "github.com/mmcdole/gofeed",
93+
"repository": "https://github.com/mmcdole/gofeed",
94+
"revision": "1bc2cbeba25b7b594430cff43d7c9e9367cfdca0",
95+
"branch": "HEAD"
96+
},
97+
{
98+
"importpath": "github.com/mmcdole/goxpp",
99+
"repository": "https://github.com/mmcdole/goxpp",
100+
"revision": "e38884aa48c1952a416ba35f3c276e4f02f9b40e",
101+
"branch": "master"
102+
},
73103
{
74104
"importpath": "golang.org/x/net/context",
75105
"repository": "https://go.googlesource.com/net",
76106
"revision": "6a513affb38dc9788b449d59ffed099b8de18fa0",
77107
"branch": "master",
78108
"path": "/context"
79109
},
110+
{
111+
"importpath": "golang.org/x/net/html",
112+
"repository": "https://go.googlesource.com/net",
113+
"revision": "a333c534c871727fb95745870e8b98a69447f2ce",
114+
"branch": "master",
115+
"path": "/html"
116+
},
80117
{
81118
"importpath": "golang.org/x/oauth2",
82119
"repository": "https://go.googlesource.com/oauth2",
83120
"revision": "1364adb2c63445016c5ed4518fc71f6a3cda6169",
84121
"branch": "master"
85122
},
123+
{
124+
"importpath": "golang.org/x/text/encoding",
125+
"repository": "https://go.googlesource.com/text",
126+
"revision": "a7c023693a94aedd6b6df43ae7526bfe9d2b7d22",
127+
"branch": "master",
128+
"path": "/encoding"
129+
},
130+
{
131+
"importpath": "golang.org/x/text/internal/tag",
132+
"repository": "https://go.googlesource.com/text",
133+
"revision": "a7c023693a94aedd6b6df43ae7526bfe9d2b7d22",
134+
"branch": "master",
135+
"path": "/internal/tag"
136+
},
137+
{
138+
"importpath": "golang.org/x/text/internal/utf8internal",
139+
"repository": "https://go.googlesource.com/text",
140+
"revision": "a7c023693a94aedd6b6df43ae7526bfe9d2b7d22",
141+
"branch": "master",
142+
"path": "/internal/utf8internal"
143+
},
144+
{
145+
"importpath": "golang.org/x/text/language",
146+
"repository": "https://go.googlesource.com/text",
147+
"revision": "a7c023693a94aedd6b6df43ae7526bfe9d2b7d22",
148+
"branch": "master",
149+
"path": "/language"
150+
},
151+
{
152+
"importpath": "golang.org/x/text/runes",
153+
"repository": "https://go.googlesource.com/text",
154+
"revision": "a7c023693a94aedd6b6df43ae7526bfe9d2b7d22",
155+
"branch": "master",
156+
"path": "/runes"
157+
},
158+
{
159+
"importpath": "golang.org/x/text/transform",
160+
"repository": "https://go.googlesource.com/text",
161+
"revision": "a7c023693a94aedd6b6df43ae7526bfe9d2b7d22",
162+
"branch": "master",
163+
"path": "/transform"
164+
},
86165
{
87166
"importpath": "google.golang.org/cloud/compute/metadata",
88167
"repository": "https://code.googlesource.com/gocloud",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Copyright (c) 2012-2016, Martin Angers & Contributors
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5+
6+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7+
8+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9+
10+
* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11+
12+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# goquery - a little like that j-thing, only in Go [![build status](https://secure.travis-ci.org/PuerkitoBio/goquery.png)](http://travis-ci.org/PuerkitoBio/goquery) [![GoDoc](https://godoc.org/github.com/PuerkitoBio/goquery?status.png)](http://godoc.org/github.com/PuerkitoBio/goquery)
2+
3+
goquery brings a syntax and a set of features similar to [jQuery][] to the [Go language][go]. It is based on Go's [net/html package][html] and the CSS Selector library [cascadia][]. Since the net/html parser returns nodes, and not a full-featured DOM tree, jQuery's stateful manipulation functions (like height(), css(), detach()) have been left off.
4+
5+
Also, because the net/html parser requires UTF-8 encoding, so does goquery: it is the caller's responsibility to ensure that the source document provides UTF-8 encoded HTML. See the [wiki][] for various options to do this.
6+
7+
Syntax-wise, it is as close as possible to jQuery, with the same function names when possible, and that warm and fuzzy chainable interface. jQuery being the ultra-popular library that it is, I felt that writing a similar HTML-manipulating library was better to follow its API than to start anew (in the same spirit as Go's `fmt` package), even though some of its methods are less than intuitive (looking at you, [index()][index]...).
8+
9+
## Installation
10+
11+
Please note that because of the net/html dependency, goquery requires Go1.1+.
12+
13+
$ go get github.com/PuerkitoBio/goquery
14+
15+
(optional) To run unit tests:
16+
17+
$ cd $GOPATH/src/github.com/PuerkitoBio/goquery
18+
$ go test
19+
20+
(optional) To run benchmarks (warning: it runs for a few minutes):
21+
22+
$ cd $GOPATH/src/github.com/PuerkitoBio/goquery
23+
$ go test -bench=".*"
24+
25+
## Changelog
26+
27+
**Note that goquery's API is now stable, and will not break.**
28+
29+
* **2016-08-28 (v1.0.1)** : Optimize performance for large documents.
30+
* **2016-07-27 (v1.0.0)** : Tag version 1.0.0.
31+
* **2016-06-15** : Invalid selector strings internally compile to a `Matcher` implementation that never matches any node (instead of a panic). So for example, `doc.Find("~")` returns an empty `*Selection` object.
32+
* **2016-02-02** : Add `NodeName` utility function similar to the DOM's `nodeName` property. It returns the tag name of the first element in a selection, and other relevant values of non-element nodes (see godoc for details). Add `OuterHtml` utility function similar to the DOM's `outerHTML` property (named `OuterHtml` in small caps for consistency with the existing `Html` method on the `Selection`).
33+
* **2015-04-20** : Add `AttrOr` helper method to return the attribute's value or a default value if absent. Thanks to [piotrkowalczuk][piotr].
34+
* **2015-02-04** : Add more manipulation functions - Prepend* - thanks again to [Andrew Stone][thatguystone].
35+
* **2014-11-28** : Add more manipulation functions - ReplaceWith*, Wrap* and Unwrap - thanks again to [Andrew Stone][thatguystone].
36+
* **2014-11-07** : Add manipulation functions (thanks to [Andrew Stone][thatguystone]) and `*Matcher` functions, that receive compiled cascadia selectors instead of selector strings, thus avoiding potential panics thrown by goquery via `cascadia.MustCompile` calls. This results in better performance (selectors can be compiled once and reused) and more idiomatic error handling (you can handle cascadia's compilation errors, instead of recovering from panics, which had been bugging me for a long time). Note that the actual type expected is a `Matcher` interface, that `cascadia.Selector` implements. Other matcher implementations could be used.
37+
* **2014-11-06** : Change import paths of net/html to golang.org/x/net/html (see https://groups.google.com/forum/#!topic/golang-nuts/eD8dh3T9yyA). Make sure to update your code to use the new import path too when you call goquery with `html.Node`s.
38+
* **v0.3.2** : Add `NewDocumentFromReader()` (thanks jweir) which allows creating a goquery document from an io.Reader.
39+
* **v0.3.1** : Add `NewDocumentFromResponse()` (thanks assassingj) which allows creating a goquery document from an http response.
40+
* **v0.3.0** : Add `EachWithBreak()` which allows to break out of an `Each()` loop by returning false. This function was added instead of changing the existing `Each()` to avoid breaking compatibility.
41+
* **v0.2.1** : Make go-getable, now that [go.net/html is Go1.0-compatible][gonet] (thanks to @matrixik for pointing this out).
42+
* **v0.2.0** : Add support for negative indices in Slice(). **BREAKING CHANGE** `Document.Root` is removed, `Document` is now a `Selection` itself (a selection of one, the root element, just like `Document.Root` was before). Add jQuery's Closest() method.
43+
* **v0.1.1** : Add benchmarks to use as baseline for refactorings, refactor Next...() and Prev...() methods to use the new html package's linked list features (Next/PrevSibling, FirstChild). Good performance boost (40+% in some cases).
44+
* **v0.1.0** : Initial release.
45+
46+
## API
47+
48+
goquery exposes two structs, `Document` and `Selection`, and the `Matcher` interface. Unlike jQuery, which is loaded as part of a DOM document, and thus acts on its containing document, goquery doesn't know which HTML document to act upon. So it needs to be told, and that's what the `Document` type is for. It holds the root document node as the initial Selection value to manipulate.
49+
50+
jQuery often has many variants for the same function (no argument, a selector string argument, a jQuery object argument, a DOM element argument, ...). Instead of exposing the same features in goquery as a single method with variadic empty interface arguments, statically-typed signatures are used following this naming convention:
51+
52+
* When the jQuery equivalent can be called with no argument, it has the same name as jQuery for the no argument signature (e.g.: `Prev()`), and the version with a selector string argument is called `XxxFiltered()` (e.g.: `PrevFiltered()`)
53+
* When the jQuery equivalent **requires** one argument, the same name as jQuery is used for the selector string version (e.g.: `Is()`)
54+
* The signatures accepting a jQuery object as argument are defined in goquery as `XxxSelection()` and take a `*Selection` object as argument (e.g.: `FilterSelection()`)
55+
* The signatures accepting a DOM element as argument in jQuery are defined in goquery as `XxxNodes()` and take a variadic argument of type `*html.Node` (e.g.: `FilterNodes()`)
56+
* The signatures accepting a function as argument in jQuery are defined in goquery as `XxxFunction()` and take a function as argument (e.g.: `FilterFunction()`)
57+
* The goquery methods that can be called with a selector string have a corresponding version that take a `Matcher` interface and are defined as `XxxMatcher()` (e.g.: `IsMatcher()`)
58+
59+
Utility functions that are not in jQuery but are useful in Go are implemented as functions (that take a `*Selection` as parameter), to avoid a potential naming clash on the `*Selection`'s methods (reserved for jQuery-equivalent behaviour).
60+
61+
The complete [godoc reference documentation can be found here][doc].
62+
63+
Please note that Cascadia's selectors do not necessarily match all supported selectors of jQuery (Sizzle). See the [cascadia project][cascadia] for details. Invalid selector strings compile to a `Matcher` that fails to match any node. Behaviour of the various functions that take a selector string as argument follows from that fact, e.g. (where `~` is an invalid selector string):
64+
65+
* `Find("~")` returns an empty selection because the selector string doesn't match anything.
66+
* `Add("~")` returns a new selection that holds the same nodes as the original selection, because it didn't add any node (selector string didn't match anything).
67+
* `ParentsFiltered("~")` returns an empty selection because the selector string doesn't match anything.
68+
* `ParentsUntil("~")` returns all parents of the selection because the selector string didn't match any element to stop before the top element.
69+
70+
## Examples
71+
72+
See some tips and tricks in the [wiki][].
73+
74+
Adapted from example_test.go:
75+
76+
```Go
77+
package main
78+
79+
import (
80+
"fmt"
81+
"log"
82+
83+
"github.com/PuerkitoBio/goquery"
84+
)
85+
86+
func ExampleScrape() {
87+
doc, err := goquery.NewDocument("http://metalsucks.net")
88+
if err != nil {
89+
log.Fatal(err)
90+
}
91+
92+
// Find the review items
93+
doc.Find(".sidebar-reviews article .content-block").Each(func(i int, s *goquery.Selection) {
94+
// For each item found, get the band and title
95+
band := s.Find("a").Text()
96+
title := s.Find("i").Text()
97+
fmt.Printf("Review %d: %s - %s\n", i, band, title)
98+
})
99+
}
100+
101+
func main() {
102+
ExampleScrape()
103+
}
104+
```
105+
106+
## License
107+
108+
The [BSD 3-Clause license][bsd], the same as the [Go language][golic]. Cascadia's license is [here][caslic].
109+
110+
[jquery]: http://jquery.com/
111+
[go]: http://golang.org/
112+
[cascadia]: https://github.com/andybalholm/cascadia
113+
[bsd]: http://opensource.org/licenses/BSD-3-Clause
114+
[golic]: http://golang.org/LICENSE
115+
[caslic]: https://github.com/andybalholm/cascadia/blob/master/LICENSE
116+
[doc]: http://godoc.org/github.com/PuerkitoBio/goquery
117+
[index]: http://api.jquery.com/index/
118+
[gonet]: https://github.com/golang/net/
119+
[html]: http://godoc.org/golang.org/x/net/html
120+
[wiki]: https://github.com/PuerkitoBio/goquery/wiki/Tips-and-tricks
121+
[thatguystone]: https://github.com/thatguystone
122+
[piotr]: https://github.com/piotrkowalczuk

0 commit comments

Comments
 (0)