Replace prazdnikisegodnyaru with celebratoday, small underhood fixes
- Replace prazdnikisegodnyaru with celebratoday as first is banned in Russia - Update .golangci.yml rule set - Megatons of fixes for linter - Update README.md
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Package flickr implements flickr.com service client.
|
||||
package flickr
|
||||
|
||||
import (
|
||||
@@ -17,27 +18,29 @@ import (
|
||||
"gopkg.in/masci/flickr.v3/test"
|
||||
)
|
||||
|
||||
// SearchResult структура, описывающая ответ api на поисковой запрос.
|
||||
type SearchResult struct {
|
||||
Photos struct {
|
||||
Page int64 `json:"page,omitempty"`
|
||||
Pages int64 `json:"pages,omitempty"`
|
||||
Perpage int64 `json:"perpage,omitempty"`
|
||||
Total int64 `json:"total,omitempty"`
|
||||
Photo []struct {
|
||||
Farm int64 `json:"farm,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Isfamily int64 `json:"isfamily,omitempty"`
|
||||
Isfriend int64 `json:"isfriend,omitempty"`
|
||||
Ispublic int64 `json:"ispublic,omitempty"`
|
||||
Owner string `json:"owner,omitempty"`
|
||||
Secret string `json:"secret,omitempty"`
|
||||
Server string `json:"server,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
} `json:"photo,omitempty"`
|
||||
} `json:"photos,omitempty"`
|
||||
Stat string `json:"stat,omitempty"`
|
||||
}
|
||||
type (
|
||||
// SearchResult структура, описывающая ответ api на поисковой запрос.
|
||||
SearchResult struct { //nolint: govet // Идите в пень, мне так удобнее.
|
||||
Photos struct { //nolint: govet // Идите в пень, мне так удобнее.
|
||||
Page int64 `json:"page,omitempty"`
|
||||
Pages int64 `json:"pages,omitempty"`
|
||||
Perpage int64 `json:"perpage,omitempty"`
|
||||
Total int64 `json:"total,omitempty"`
|
||||
Photo []struct { //nolint: govet // Идите в пень, мне так удобнее.
|
||||
Farm int64 `json:"farm,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Isfamily int64 `json:"isfamily,omitempty"`
|
||||
Isfriend int64 `json:"isfriend,omitempty"`
|
||||
Ispublic int64 `json:"ispublic,omitempty"`
|
||||
Owner string `json:"owner,omitempty"`
|
||||
Secret string `json:"secret,omitempty"`
|
||||
Server string `json:"server,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
} `json:"photo"`
|
||||
} `json:"photos"`
|
||||
Stat string `json:"stat,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
// APIClientInit генерит и сохраняет token и token secret с помощью даденных пользователем key и secret.
|
||||
// В процессе выдаём юзеру в консоль урл и запрос открыть его в браузере, чтобы получить verifier key, который нам
|
||||
@@ -47,15 +50,15 @@ func APIClientInit(cfg *config.MyConfig) error {
|
||||
|
||||
client := flickr.NewFlickrClient(cfg.Flickr.Key, cfg.Flickr.Secret)
|
||||
|
||||
// Первым делом достанем request token
|
||||
// Первым делом достанем request token.
|
||||
tok, err := flickr.GetRequestToken(client)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get Request Token: %w", err)
|
||||
}
|
||||
|
||||
// Соорудим авторизационный URL
|
||||
url, err := flickr.GetAuthorizeUrl(client, tok)
|
||||
// Соорудим авторизационный URL.
|
||||
link, err := flickr.GetAuthorizeUrl(client, tok)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get auth URL: %w", err)
|
||||
@@ -63,11 +66,12 @@ func APIClientInit(cfg *config.MyConfig) error {
|
||||
|
||||
// А теперь ручные действия пользователя.
|
||||
// Выдаём ему url, который надо ввести в адресную строку браузера, в браузере сгенерится verifier code, который нам
|
||||
// нужен, чтобы вынуть из flicker api oauth token, secret, access token
|
||||
// нужен, чтобы вынуть из flicker api oauth token, secret, access token.
|
||||
var oauthVerifier string
|
||||
|
||||
fmt.Println("Open your browser at this url:", url)
|
||||
fmt.Println("Open your browser at this url:", link)
|
||||
fmt.Print("Then, insert the code: ")
|
||||
|
||||
_, _ = fmt.Scanln(&oauthVerifier)
|
||||
|
||||
// Наконец, достаём Access Token и Aceess Token Secret и сохраняем их в базку на диске.
|
||||
@@ -127,7 +131,8 @@ func SearchByTags(cfg *config.MyConfig, tags []string) (string, error) {
|
||||
)
|
||||
|
||||
// Заполняем поля для оаутха.
|
||||
c.Init() // c.EndpointUrl
|
||||
c.Init()
|
||||
|
||||
c.OAuthToken = oauthToken
|
||||
c.OAuthTokenSecret = oauthSecret
|
||||
|
||||
@@ -152,12 +157,12 @@ func SearchByTags(cfg *config.MyConfig, tags []string) (string, error) {
|
||||
// разметки, а во-вторых, этот самый flickr.DoGet() валится с segfault-ом, просто потому что. Схема не такая, на
|
||||
// которую он рассчитан. Но нам повезло, что можно просто вытащить подписанный url и заправить его в свой
|
||||
// http-клиент.
|
||||
url := c.GetUrl()
|
||||
link := c.GetUrl()
|
||||
|
||||
var response SearchResult
|
||||
|
||||
err := requests.
|
||||
URL(url).
|
||||
URL(link).
|
||||
UserAgent(userAgent).
|
||||
ToJSON(&response).
|
||||
Fetch(ctx)
|
||||
@@ -179,10 +184,10 @@ func SearchByTags(cfg *config.MyConfig, tags []string) (string, error) {
|
||||
// Подписываем запрос oauth-говном.
|
||||
c.OAuthSign()
|
||||
|
||||
url = c.GetUrl()
|
||||
link = c.GetUrl()
|
||||
|
||||
err = requests.
|
||||
URL(url).
|
||||
URL(link).
|
||||
UserAgent(userAgent).
|
||||
ToJSON(&response).
|
||||
Fetch(ctx)
|
||||
@@ -200,10 +205,10 @@ func SearchByTags(cfg *config.MyConfig, tags []string) (string, error) {
|
||||
|
||||
var u SearchResult
|
||||
|
||||
for i := 0; i < len(response.Photos.Photo); i++ {
|
||||
for i := range len(response.Photos.Photo) {
|
||||
skip := false
|
||||
|
||||
for j := 0; j < len(u.Photos.Photo); j++ {
|
||||
for j := range len(u.Photos.Photo) {
|
||||
if response.Photos.Photo[i].Title == u.Photos.Photo[j].Title {
|
||||
skip = true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user