How to use Seventeen method of source Package

Best Mock code snippet using source.Seventeen

selenium_seventeen.go

Source:selenium_seventeen.go Github

copy

Full Screen

...13)14var (15 seventeenURL = "https://17.live/suggested"16)17type seleniumSeventeenRepository struct{}18// NewSeleniumSeventeenRepository is new a seleniumSeventeenRepository struct19func NewSeleniumSeventeenRepository() seventeen.Repository {20 return &seleniumSeventeenRepository{}21}22func (seventeenRepo *seleniumSeventeenRepository) Init(config resource.Config) {23 log.Println("[Seventeen] START")24 defer log.Println("[Seventeen] END")25 port, gerFreePortErr := resource.GetFreePort()26 if gerFreePortErr != nil {27 resource.HandleError(gerFreePortErr, "[Seventeen] gerFreePortErr")28 return29 }30 service, getServiceErr := resource.GetService(port)31 if getServiceErr != nil {32 resource.HandleError(getServiceErr, "[Seventeen] getServiceErr")33 return34 }35 defer service.Stop()36 wd, getRemoteErr := resource.GetRemote(port)37 if getRemoteErr != nil {38 resource.HandleError(getRemoteErr, "[Seventeen] getRemoteErr")39 return40 }41 defer wd.Quit()42 frameHTML, getDataFromStreamListErr := seventeenRepo.getStreamListHTML(wd, seventeenURL)43 if getDataFromStreamListErr != nil {44 resource.HandleError(getDataFromStreamListErr, "[Seventeen] getDataFromStreamListErr")45 return46 }47 datas, parseStreamListErr := seventeenRepo.parseStreamListHTML(frameHTML)48 if parseStreamListErr != nil {49 resource.HandleError(parseStreamListErr, "[Seventeen] parseStreamListErr")50 return51 }52 for _, data := range datas {53 resource.SendToElasticByHTTPPost(data, config)54 }55 log.Println("Total streams are ", len(datas))56}57func (seventeenRepo *seleniumSeventeenRepository) getStreamListHTML(wd selenium.WebDriver, url string) (string, error) {58 if wd == nil {59 err := errors.New("[Seventeen] wd is nil")60 return "", err61 }62 wd.Get(url)63 wd.MaximizeWindow("")64 time.Sleep(3000 * time.Millisecond)65 wd.ExecuteScript("window.scrollTo(0,5000)", nil)66 time.Sleep(15 * time.Second)67 frameHTML, pageSourceErr := wd.PageSource()68 return frameHTML, pageSourceErr69}70func (seventeenRepo *seleniumSeventeenRepository) parseStreamListHTML(frameHTML string) (datas []resource.Data, err error) {71 doc, newDocumentFromReaderErr := goquery.NewDocumentFromReader(bytes.NewReader([]byte(frameHTML)))72 if newDocumentFromReaderErr != nil {73 resource.HandleError(newDocumentFromReaderErr, "[Seventeen] newDocumentFromReaderErr")74 return nil, newDocumentFromReaderErr75 }76 doc.Find("div.Grid__Row-eThVWD").Find("div.LiveStreamBlock__Block-bdJheI").Each(func(i int, s *goquery.Selection) {77 title := seventeenRepo.getTitle(s)78 thumbnails := seventeenRepo.getThumbnails(s)79 localTime := resource.GetLocalTime()80 viewers, getViewersErr := seventeenRepo.getViewers(s)81 if getViewersErr != nil {82 resource.HandleError(getViewersErr, "[Seventeen] getViewersErr")83 err = getViewersErr84 return85 }86 videoURL, isVideoURLExist := seventeenRepo.getVideoURL(s)87 if !isVideoURLExist {88 err = errors.New("VideoURL not Exist")89 return90 }91 data := resource.Data{92 Title: title,93 Description: "",94 Platform: "17直播",95 VideoID: "",96 Host: title,97 Status: "live",98 Thumbnails: thumbnails,99 Published: localTime,100 Tags: "",101 GeneralTag: "",102 Timestamp: localTime,103 Language: "zh",104 ViewCount: viewers,105 Viewers: viewers,106 VideoURL: videoURL,107 VideoEmbedded: "",108 ChatRoomEmbedded: "",109 Channel: "",110 }111 datas = append(datas, data)112 })113 return114}115func (seventeenRepo *seleniumSeventeenRepository) getTitle(s *goquery.Selection) string {116 title, _ := s.Find("a").Attr("title")117 return title118}119func (seventeenRepo *seleniumSeventeenRepository) getThumbnails(s *goquery.Selection) string {120 thumbnails, _ := s.Find("a").Find("div.LiveStreamBlock__AvatarWrapper-CSDSj").Attr("style")121 thumbnails = thumbnails[strings.Index(thumbnails, "url(\"")+5:]122 thumbnails = thumbnails[:strings.Index(thumbnails, "url(\"")-4]123 return thumbnails124}125func (seventeenRepo *seleniumSeventeenRepository) getViewers(s *goquery.Selection) (int, error) {126 viewersStr := s.Find("a").Find("span.Msg-eAZFzz").Text()127 viewersStr = strings.Replace(viewersStr, ",", "", -1)128 if viewersStr == "ON AIR" {129 return 0, nil130 }131 viewers, atoiErr := strconv.Atoi(viewersStr)132 return viewers, atoiErr133}134func (seventeenRepo *seleniumSeventeenRepository) getVideoURL(s *goquery.Selection) (string, bool) {135 url, isVideoURLExist := s.Find("a").Attr("href")136 return "https://17.live" + url, isVideoURLExist137}138func (seventeenRepo *seleniumSeventeenRepository) ParseStreamURLHTML(wd selenium.WebDriver, videoURLs []string) (datas []resource.Data, err error) {139 for _, url := range videoURLs {140 frameHTML, getStreamURLHTMLErr := seventeenRepo.getStreamURLHTML(wd, url)141 if getStreamURLHTMLErr != nil {142 resource.HandleError(getStreamURLHTMLErr, "[Seventeen] getStreamURLHTMLErr")143 break144 }145 doc, newDocumentFromReaderErr := goquery.NewDocumentFromReader(bytes.NewReader([]byte(frameHTML)))146 if newDocumentFromReaderErr != nil {147 resource.HandleError(newDocumentFromReaderErr, "[Seventeen] newDocumentFromReaderErr")148 break149 }150 title := seventeenRepo.getTitleFromHost(doc)151 thumbnails := seventeenRepo.getThumbnailsFromHost(doc)152 viewers := seventeenRepo.getViewersFromHost(doc)153 localTime := resource.GetLocalTime()154 data := resource.Data{155 Title: title,156 Description: "",157 Platform: "17直播",158 VideoID: "",159 Host: title,160 Status: "live",161 Thumbnails: thumbnails,162 Published: localTime,163 Tags: "",164 GeneralTag: "",165 Timestamp: localTime,166 Language: "zh",167 ViewCount: viewers,168 Viewers: viewers,169 VideoURL: url,170 VideoEmbedded: "",171 ChatRoomEmbedded: "",172 Channel: "",173 }174 log.Printf("%+v", data)175 datas = append(datas, data)176 }177 return178}179func (seventeenRepo *seleniumSeventeenRepository) getStreamURLHTML(wd selenium.WebDriver, url string) (string, error) {180 wd.Get(url)181 time.Sleep(3000 * time.Millisecond)182 frameHTML, pageSourceErr := wd.PageSource()183 return frameHTML, pageSourceErr184}185func (seventeenRepo *seleniumSeventeenRepository) getTitleFromHost(s *goquery.Document) string {186 return s.Find("a.StreamerInfo__StreamerName-hcwkwO").Text()187}188func (seventeenRepo *seleniumSeventeenRepository) getThumbnailsFromHost(s *goquery.Document) string {189 thumbnails, _ := s.Find("div.StreamerInfo__StreamerInfoWrapper-bWkiCI").Find("div.withFadeIn__Com-dcgmuw").Attr("style")190 thumbnails = thumbnails[strings.Index(thumbnails, "url(\"")+5:]191 thumbnails = thumbnails[:strings.Index(thumbnails, "url(\"")-4]192 return thumbnails193}194func (seventeenRepo *seleniumSeventeenRepository) getViewersFromHost(s *goquery.Document) int {195 return 0196}...

Full Screen

Full Screen

seventeenK.go

Source:seventeenK.go Github

copy

Full Screen

...4 "net/url"5 "strings"6 "github.com/PuerkitoBio/goquery"7)8//SeventeenKReader 纵横小说网9type SeventeenKReader struct {10}11// GetCategories 获取所有分类12func (r SeventeenKReader) GetCategories(urlStr string) (list Catalog, err error) {13 // urlStr := `http://book.17k.com`14 list.Title = `17K小说网`15 list.SourceURL = urlStr16 list.Hash = GetCatalogHash(list)17 list.Cards = []Card{18 Card{`奇幻玄幻`, `/pages/list?action=book&drive=17k&url=` + EncodeURL(`https://www.17k.com/all/book/2_21_0_0_0_0_0_0_1.html`), "", `link`, ``, nil, ``, ``},19 Card{`武侠仙侠`, `/pages/list?action=book&drive=17k&url=` + EncodeURL(`https://www.17k.com/all/book/2_24_0_0_0_0_0_0_1.html`), "", `link`, ``, nil, ``, ``},20 Card{`都市小说`, `/pages/list?action=book&drive=17k&url=` + EncodeURL(`https://www.17k.com/all/book/2_3_0_0_0_0_0_0_1.html`), "", `link`, ``, nil, ``, ``},21 Card{`历史军事`, `/pages/list?action=book&drive=17k&url=` + EncodeURL(`https://www.17k.com/all/book/2_22_0_0_0_0_0_0_1.html`), "", `link`, ``, nil, ``, ``},22 Card{`游戏竞技`, `/pages/list?action=book&drive=17k&url=` + EncodeURL(`https://www.17k.com/all/book/2_23_0_0_0_0_0_0_1.html`), "", `link`, ``, nil, ``, ``},23 Card{`科幻末世`, `/pages/list?action=book&drive=17k&url=` + EncodeURL(`https://www.17k.com/all/book/2_14_0_0_0_0_0_0_1.html`), "", `link`, ``, nil, ``, ``},24 Card{`古装言情`, `/pages/list?action=book&drive=17k&url=` + EncodeURL(`https://www.17k.com/all/book/3_5_0_0_0_0_0_0_1.html`), "", `link`, ``, nil, ``, ``},25 Card{`都市言情`, `/pages/list?action=book&drive=17k&url=` + EncodeURL(`https://www.17k.com/all/book/3_17_0_0_0_0_0_0_1.html`), "", `link`, ``, nil, ``, ``},26 Card{`浪漫青春`, `/pages/list?action=book&drive=17k&url=` + EncodeURL(`https://www.17k.com/all/book/3_20_0_0_0_0_0_0_1.html`), "", `link`, ``, nil, ``, ``},27 Card{`幻想言情`, `/pages/list?action=book&drive=17k&url=` + EncodeURL(`https://www.17k.com/all/book/3_18_0_0_0_0_0_0_1.html`), "", `link`, ``, nil, ``, ``},28 }29 list.SearchSupport = true30 return list, nil31}32// GetList 获取书籍列表列表33func (r SeventeenKReader) GetList(urlStr string) (list Catalog, err error) {34 err = CheckStrIsLink(urlStr)35 if err != nil {36 return37 }38 html, err := GetHTML(urlStr, ``)39 if err != nil {40 return41 }42 g, e := goquery.NewDocumentFromReader(strings.NewReader(html))43 if e != nil {44 return list, e45 }46 list.Title = g.Find("title").Text()47 link, _ := url.Parse(urlStr)48 var links = GetLinks(g, link)49 var needLinks []Link50 var state bool51 for _, l := range links {52 l.URL, state = JaccardMateGetURL(l.URL, `https://www.17k.com/book/2897539.html`, `https://www.17k.com/book/2927482.html`, `https://www.17k.com/list/2897539.html`)53 if state {54 needLinks = append(needLinks, l)55 }56 }57 list.Cards = LinksToCards(Cleaning(needLinks), `/pages/catalog`, `17k`)58 list.SourceURL = urlStr59 list.Next = GetNextLink(links)60 if list.Next.URL != `` {61 list.Next.URL = EncodeURL(list.Next.URL)62 }63 list.Hash = GetCatalogHash(list)64 return list, nil65}66// Search 搜索资源67func (r SeventeenKReader) Search(keyword string) (list Catalog, err error) {68 urlStr := `https://search.17k.com/search.xhtml?c.st=0&c.q=` + keyword69 err = CheckStrIsLink(urlStr)70 if err != nil {71 return72 }73 html, err := GetHTML(urlStr, ``)74 if err != nil {75 return76 }77 g, e := goquery.NewDocumentFromReader(strings.NewReader(html))78 if e != nil {79 return list, e80 }81 list.Title = fmt.Sprintf(`%v - 搜索结果 - 17k.com`, keyword)82 link, _ := url.Parse(urlStr)83 var links = GetLinks(g, link)84 var needLinks []Link85 var state bool86 for _, l := range links {87 l.URL, state = JaccardMateGetURL(l.URL, `https://www.17k.com/book/2897539.html`, `https://www.17k.com/book/2927482.html`, `https://www.17k.com/list/2897539.html`)88 if state {89 needLinks = append(needLinks, l)90 }91 }92 list.Cards = LinksToCards(Cleaning(needLinks), `/pages/catalog`, `17k`)93 list.SourceURL = urlStr94 list.Hash = GetCatalogHash(list)95 return list, nil96}97// GetCatalog 获取章节列表98func (r SeventeenKReader) GetCatalog(urlStr string) (list Catalog, err error) {99 err = CheckStrIsLink(urlStr)100 if err != nil {101 return102 }103 html, err := GetHTML(urlStr, ``)104 if err != nil {105 return106 }107 g, e := goquery.NewDocumentFromReader(strings.NewReader(html))108 if e != nil {109 return list, e110 }111 list.Title = FindString(`(?P<title>(.)+)_(?P<author>(.)+)_作品目录`, g.Find("title").Text(), "title")112 if list.Title == `` {113 list.Title = g.Find("title").Text()114 }115 link, _ := url.Parse(urlStr)116 var links = GetLinks(g, link)117 var needLinks []Link118 var state bool119 for _, l := range links {120 l.URL, state = JaccardMateGetURL(l.URL, `https://www.17k.com/chapter/2927485/36602417.html`, `https://www.17k.com/chapter/493239/36611963.html`, ``)121 if state {122 needLinks = append(needLinks, l)123 }124 }125 list.Cards = LinksToCards(Cleaning(needLinks), `/pages/book`, `17k`)126 list.SourceURL = urlStr127 list.Hash = GetCatalogHash(list)128 return list, nil129}130// GetInfo 获取详细内容131func (r SeventeenKReader) GetInfo(urlStr string) (ret Content, err error) {132 err = CheckStrIsLink(urlStr)133 if err != nil {134 return135 }136 html, err := GetHTML(urlStr, ``)137 if err != nil {138 return ret, err139 }140 // log.Println(html)141 article, err := GetActicleByHTML(html)142 if err != nil {143 return ret, err144 }145 article.Readable(urlStr)...

Full Screen

Full Screen

jobconfig_test.go

Source:jobconfig_test.go Github

copy

Full Screen

1/*2 * Copyright 2021 The KubeVirt Authors.3 * Licensed under the Apache License, Version 2.0 (the "License");4 * you may not use this file except in compliance with the License.5 * You may obtain a copy of the License at6 * http://www.apache.org/licenses/LICENSE-2.07 * Unless required by applicable law or agreed to in writing, software8 * distributed under the License is distributed on an "AS IS" BASIS,9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10 * See the License for the specific language governing permissions and11 * limitations under the License.12 *13 */14package prowjobconfigs15import "testing"16func Test_AdvanceCronExpression(t *testing.T) {17 type args struct {18 sourceCronExpr string19 }20 tests := []struct {21 name string22 args args23 want string24 }{25 {26 name: "zero one nine seventeen",27 args: args{28 sourceCronExpr: "0 1,9,17 * * *",29 },30 want: "10 2,10,18 * * *",31 },32 {33 name: "fifty one nine seventeen",34 args: args{35 sourceCronExpr: "50 1,9,17 * * *",36 },37 want: "0 2,10,18 * * *",38 },39 {40 name: "zero eight sixteen twentyfour",41 args: args{42 sourceCronExpr: "0 8,16,24 * * *",43 },44 want: "10 1,9,17 * * *",45 },46 {47 name: "zero seven fifteen twentythree",48 args: args{49 sourceCronExpr: "0 7,15,23 * * *",50 },51 want: "10 0,8,16 * * *",52 },53 }54 for _, tt := range tests {55 t.Run(tt.name, func(t *testing.T) {56 if got := AdvanceCronExpression(tt.args.sourceCronExpr); got != tt.want {57 t.Errorf("AdvanceCronExpression() = %v, want %v", got, tt.want)58 }59 })60 }61}...

Full Screen

Full Screen

Seventeen

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 source.Seventeen()4}5import (6func Seventeen() {7 fmt.Println("Seventeen")8}9I am new to go and I am trying to import a package from another folder. I am getting error: cannot find package "source" in any of: /usr/local/go/src/source (from $GOROOT) /home/raghav/go/src/source (from $GOPATH) I am using go version go1.10.1 linux/amd6410I am trying to create a simple program that will print the number 17 to the console. I am new to Go and am trying to learn the language. I am using the Go Playground. I have tried the following code: package main import "fmt" func main() { fmt.Println("17") } But I get the following error: 17.go:4:2: cannot find package "fmt" in any of: /usr/local/go/src/fmt (from $GOROOT) /tmp/17.go:4:2: cannot find package "fmt" in any of: /usr/local/go/src/fmt (from $GOROOT) /tmp/17.go:4:2: cannot find package "fmt" in any of: /usr/local/go/src/fmt (from $GOROOT) /tmp/17.go:4:2: cannot find package "fmt" in any of: /usr/local/go/src/fmt (from $GOROOT) /tmp/17.go:4:2: cannot find package "fmt" in any of: /usr/local/go/src/fmt (from $GOROOT) /tmp/17.go:4:2: cannot find package "fmt" in any of: /usr/local/go/src/fmt (from $GOROOT) /tmp/17.go:4:2: cannot find package "fmt" in any of: /usr/local/go/src/fmt (from $GOROOT) /tmp/17.go:4:2: cannot find package "fmt" in any of: /usr/local/go/src/fmt (from $GOROOT) /tmp/17.go:4:2: cannot find package "fmt" in any of: /usr/local/go/src/fmt (from $GOROOT) /tmp/17.go:

Full Screen

Full Screen

Seventeen

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "source"3func main() {4 fmt.Println(source.Seventeen())5}6func Seventeen() int {7}8import "testing"9func TestSeventeen(t *testing.T) {10 if Seventeen() != 17 {11 t.Error("Seventeen() should be 17")12 }13}14The source_test directory is a sibling of the source directory. The test class imports the source class. The test class imports the source_test directory. The source class is in the source directory. The source_test directory is a sibling of the source directory. The test class imports the source class. The test class

Full Screen

Full Screen

Seventeen

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("17 is", source.Seventeen())4}5func Seventeen() int {6}

Full Screen

Full Screen

Seventeen

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("I am in main")4 source.Seventeen()5}6import (7func Seventeen() {8 fmt.Println("I am in Seventeen")9}

Full Screen

Full Screen

Seventeen

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(source.Seventeen())4}5func Seventeen() int {6}

Full Screen

Full Screen

Seventeen

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/GoTraining/Day1/17/source"3func main() {4 source.Seventeen()5 fmt.Println("Hello World!")6}7import "fmt"8func Seventeen() {9 fmt.Println("Seventeen")10}11import "

Full Screen

Full Screen

Seventeen

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/rajeshkumarv/GoLang/Package/Source"3func main() {4 fmt.Println("Hello")5 Source.Seventeen()6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful