Ejemplo n.º 1
0
func main() {
	log := logs.NewLogger(10000)
	log.SetLogger("file", `{"filename":"/tmp/wallpaper.log"}`)
	log.Info("Start===================")
	v := Bing{}
	req := httplib.Get("http://www.bing.com/HPImageArchive.aspx?format=json&idx=0&n=1")
	err := req.ToXml(&v)

	if len(v.Images) > 0 && err == nil {
		pic := httplib.Get(bingURL + v.Images[0].Url)
		fmt.Println(file_path)
		err = pic.ToFile(file_path)
		if err != nil {
			log.Error("save file error %v.............", err)
		} else {
			log.Info("download wallpeper success..........")
			cmd := exec.Command("gsettings", "set", "org.gnome.desktop.background", "picture-uri", fmt.Sprintf("file:%s", file_path))
			err := cmd.Start()
			log.Info("Waiting for command to finish.........")
			err = cmd.Wait()
			log.Info("Command finished with error: %v", err)
			if err != nil {
				log.Error("%v............", err)
			}
			log.Info("set wallpeper success..........")
		}
	}
	log.Info("End===================")
}
Ejemplo n.º 2
0
func Logout(sig string) error {
	uri := fmt.Sprintf("%s/sso/logout/%s", UicInternal, sig)
	req := httplib.Get(uri)
	req.Param("token", Token)
	_, err := req.String()
	return err
}
Ejemplo n.º 3
0
func (this *ContectController) Get() {
	req := httplib.Get("http://acg.178.com/")
	str, err := req.String()
	if err != nil {
	}
	this.Ctx.WriteString(str)
}
Ejemplo n.º 4
0
func GetUser(sig string) (*User, error) {
	key := fmt.Sprintf("u:%s", sig)
	u := g.Cache.Get(key)
	if u != nil {
		uobj := u.(User)
		return &uobj, nil
	}

	uri := fmt.Sprintf("%s/sso/user/%s", g.UicInternal, sig)
	req := httplib.Get(uri)
	req.Param("token", g.Token)
	resp, err := req.Response()
	if err != nil {
		return nil, err
	}

	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("StatusCode: %d", resp.StatusCode)
	}

	decoder := json.NewDecoder(resp.Body)
	type TmpStruct struct {
		User *User `json:"user"`
	}
	var t TmpStruct
	err = decoder.Decode(&t)
	if err != nil {
		return nil, err
	}

	// don't worry cache expired. we just use username which can not modify
	g.Cache.Put(key, *t.User, int64(360000))

	return t.User, nil
}
Ejemplo n.º 5
0
func DeleteContainerUserFromProxy(rulelist []SshRule, logid int64) error {
	logs.Normal("delete container from proxy:", rulelist, "logid:", logid)
	token := beego.AppConfig.String("proxy_url_token")
	//userdel
	for _, sshRuleOb := range rulelist {
		container := sshRuleOb.ContainerName
		proxyHost := sshRuleOb.ProxyHost
		//this url todo
		proxyDelUrl := proxyHost + ":9090/deleteContainer?container=" + container + "&logid=" + strconv.FormatInt(logid, 10) + "&token=" + token
		logs.Normal("curl delete container url:", proxyDelUrl, "logid:", logid)

		req := httplib.Get(proxyDelUrl)
		output := make(map[string]interface{})
		err := req.ToJson(&output)
		if err != nil {
			logs.Error("request from "+proxyDelUrl+" error:", err, logid)
			return err
		}

		if output["result"].(int) == 0 {
			logs.Normal(proxyDelUrl, "response ok!", logid)
			continue
		} else {
			logs.Error(proxyDelUrl+" error:", output["error"], logid)
		}
	}
	return nil
}
Ejemplo n.º 6
0
func fetch(videoUrl string) {
	req := httplib.Get(videoUrl)
	resp, err := req.Response()
	if err != nil {
		fmt.Println("fetch video url error,", err)
		return
	}
	defer resp.Body.Close()
	respData, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("read video url content error,", err)
		return
	}
	pattern := `flashvars="list=.*"`
	regx := regexp.MustCompile(pattern)
	flashVars := regx.FindString(string(respData))
	if flashVars != "" {
		size := len(flashVars)
		m3u8Url, err := url.QueryUnescape(flashVars[16 : size-1])
		if err != nil {
			fmt.Println(err)
		} else {
			fetchMovie(m3u8Url)
		}
	} else {
		fmt.Println("m3u8 playlist not found")
	}
}
Ejemplo n.º 7
0
Archivo: ptag.go Proyecto: qgweb/gopro
// 队列操作
func httpsqsQueue(px string) url.Values {
	hurl := fmt.Sprintf("http://%s:%s/?name=%s&opt=%s&auth=%s", qshost, qsport,
		rediskey+px, "get", qsauth)

	r := httplib.Get(hurl)
	transport := http.Transport{
		DisableKeepAlives: true,
	}
	r.SetTransport(&transport)
	res, err := r.String()

	if err != nil {
		log.Println("读取http队列出错,错误信息为:", err)
		return nil
	}

	if string(res) == "HTTPSQS_GET_END" || string(res) == "HTTPSQS_ERROR" {
		return nil
	}

	res = encrypt.GetEnDecoder(encrypt.TYPE_BASE64).Decode(res)

	data, err := url.ParseQuery(res)
	if err != nil {
		log.Println("解析数据失败")
		return nil
	}

	return data
}
Ejemplo n.º 8
0
func main() {
	// resp, _ := http.Get("http://localhost:8080/gzip")
	// defer resp.Body.Close()

	// body, _ := ioutil.ReadAll(resp.Body)
	// fmt.Println(string(body))

	req := httplib.Get("http://192.168.3.151:8180/solr/judeals/select?q=*%3A*&wt=json&indent=true")
	body1, _ := req.String()
	fmt.Println(body1)

	// res, _ := goreq.Request{
	// 	Method:      "GET",
	// 	Uri:         "http://localhost:8080/gzip",
	// 	Compression: goreq.Gzip(),
	// }.Do()
	// body2, _ := res.Body.ToString()
	// fmt.Println(body2)

	// res1, _ := goreq.Request{
	// 	Method: "GET",
	// 	Uri:    "http://192.168.3.151:8180/solr/judeals/select?q=*%3A*&wt=json&indent=true",
	// 	// Compression: goreq.Gzip(),
	// }.Do()
	// body3, _ := res1.Body.ToString()
	// fmt.Println(body3)
}
Ejemplo n.º 9
0
/*
	List all the address and balance --> for update
	addSlice, err := models.ListAddress()
	fmt.Println(addSlice)
*/
func ListAddress() ([]Alladdress_callback, error) {
	url := wallet_url
	method := "list?"
	pas := firstpass
	body := httplib.Get(url+method+"password="+pas).SetTimeout(3*time.Second, 2*time.Second)
	var callback List
	err := body.ToJson(&callback)
	if err != nil {
		return []Alladdress_callback{}, err
	}

	if len(callback.AllAddress) == 0 {
		var err_callback error_callback
		err := body.ToJson(&err_callback)
		if err != nil {
			return []Alladdress_callback{}, err
		}
		return []Alladdress_callback{}, errors.New(err_callback.Error)
	}

	for i, v := range callback.AllAddress {
		callback.AllAddress[i].Balance = v.Balance / satoshi
	}
	return callback.AllAddress, nil
}
Ejemplo n.º 10
0
func (p *Facebook) GetIndentify(tok *social.Token) (string, error) {
	vals := make(map[string]interface{})

	uri := "https://graph.facebook.com/me?fields=id&access_token=" + url.QueryEscape(tok.AccessToken)
	req := httplib.Get(uri)
	req.SetTransport(social.DefaultTransport)

	resp, err := req.Response()
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	decoder := json.NewDecoder(resp.Body)
	decoder.UseNumber()

	if err := decoder.Decode(&vals); err != nil {
		return "", err
	}

	if vals["error"] != nil {
		return "", fmt.Errorf("%v", vals["error"])
	}

	if vals["id"] == nil {
		return "", nil
	}

	return fmt.Sprint(vals["id"]), nil
}
Ejemplo n.º 11
0
func (p *Github) GetIndentify(tok *social.Token) (string, error) {
	vals := make(map[string]interface{})

	uri := "https://api.github.com/user"
	req := httplib.Get(uri)
	req.SetTransport(social.DefaultTransport)
	req.Header("Authorization", "Bearer "+tok.AccessToken)

	resp, err := req.Response()
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	decoder := json.NewDecoder(resp.Body)
	decoder.UseNumber()

	if err := decoder.Decode(&vals); err != nil {
		return "", err
	}
	if resp.StatusCode != 200 {
		return "", fmt.Errorf("%v", vals["message"])
	}

	if vals["id"] == nil {
		return "", nil
	}

	return fmt.Sprint(vals["id"]), nil
}
Ejemplo n.º 12
0
func (c *MainController) Post() {

	name := c.Input().Get("name")
	regno := c.Input().Get("regNo")
	email := c.Input().Get("email")
	mobno := c.Input().Get("mobno")
	domain := c.Input().Get("domain")
	why := c.Input().Get("why")

	o := orm.NewOrm()

	management := models.Management{Name: name, RegNo: regno, Email: email, MobileNo: mobno, Domain: domain, Why: why}
	_, err := o.Insert(&management)
	if err == nil {
		message := "Congratulations, " + name + ", you have successfully registered for Connect.Create.Celebrate.%0A Date : 18th March '16%0AVenue: Bhagat Singh Gallery, SJT.%0ATime : 3:30 to 7:30%0AFrom,%0ATeam GDG VIT"
		_, err := httplib.Get("https://control.msg91.com/api/sendhttp.php?authkey=81434A3rGba9dY75583ac07&mobiles=" + mobno + "&message=" + string(message) + "&sender=GDGVIT&route=4").String()
		if err == nil {
			c.Ctx.Redirect(302, "/")
		} else {
			fmt.Println(err)
		}
	} else {
		fmt.Println(err)
	}
	c.Ctx.Redirect(302, "/")
}
Ejemplo n.º 13
0
// findFile 查询远程文件存在,仅返回200,400的数据
func (p *proxyFile) findFile() (header http.Header, data []byte, status int) {
	// chan findok int

	for _, hostStep := range p.hosts {
		url := "http://" + hostStep + p.url

		req := httplib.Get(url).SetTimeout(time.Second*10, time.Second*10)
		resp, err := req.Response()
		if err != nil {
			log.Println(err)
		}

		status = resp.StatusCode
		header = resp.Header
		log.Printf("[proxy][url]%s [%d]\n", url, status)

		if status == 200 {
			data, _ = req.Bytes()
			if conf.WriteHere {
				go writeFile(path.Join(conf.LocalDir, p.url), data)
			}
			return
		}
	}

	status = http.StatusNotFound
	data = []byte("404: File is undefined!")
	return
}
Ejemplo n.º 14
0
Archivo: misso.go Proyecto: yubo/falcon
/***********************
 * from sso_client.go
 ***********************/
func (p *missoAuth) GetUser() (string, error) {
	url := fmt.Sprintf("%s/login/broker/%s/broker_cookies/%s/user",
		p.missoAuthDomain, p.BrokerName, p.Credential)
	resp, err := httplib.Get(url).String()
	var resp_js map[string]string
	err = json.Unmarshal([]byte(resp), &resp_js)
	return resp_js["user_name"], err
}
Ejemplo n.º 15
0
/**
 * 获取http请求结果
 * 	url:请求url
 * 	data:body数据对象接口
 */
func GetHttpRequest(url string, data interface{}) (resp *ApiResp, err error) {
	req := httplib.Get(url)
	resp = &ApiResp{}
	err = req.ToJson(resp)
	//获取body数据
	err = GetRespBodyData(resp, data)
	resp.Body = &data
	return
}
Ejemplo n.º 16
0
Archivo: misso.go Proyecto: yubo/falcon
func (p *missoAuth) IsLogin() (bool, error) {
	url := fmt.Sprintf("%s/login/broker/%s/broker_cookies/%s/check",
		p.missoAuthDomain, p.BrokerName, p.Credential)
	resp, err := httplib.Get(url).String()
	if err != nil {
		return false, err
	}

	return resp == "1", nil
}
Ejemplo n.º 17
0
func test2() {
	req := httplib.Get("http://localhost:8081/test")
	httpRes, _ := req.Response()
	fmt.Println(httpRes.StatusCode)

	result := &ApiResp{}
	err := req.ToJson(result)
	fmt.Println(err)
	fmt.Println(result)
}
Ejemplo n.º 18
0
func (this *ExtractorController) Parse() {
	url := this.GetString("page_url")
	str, err := httplib.Get("http://52.35.87.105:8888/url_enter?page_url=" + url).String()
	if err != nil {
		// error
	}
	this.Data["json"] = str
	//this.ServeJSON()
	this.Ctx.Output.JSON(this.Data["json"], false, false)
}
Ejemplo n.º 19
0
func (o *ObjectController) Get() {
	req := httplib.Get("http://beego.me/")
	str, err := req.String()
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(str)

	o.Data["json"] = str
	o.ServeJson()
}
Ejemplo n.º 20
0
Archivo: newsc.go Proyecto: shaalx/news
func (c *NewsVController) story(id string) interface{} {
	hot_url := fmt.Sprintf("http://news-at.zhihu.com/api/4/story-extra/%s", id)
	resp := httplib.Get(hot_url)

	var v interface{}
	err := resp.ToJson(&v)
	if CheckErr(err) {
		return nil
	}
	return v
}
Ejemplo n.º 21
0
// @router /sections [get]
func (c *NewsController) Sections() {
	hot_url := "http://news-at.zhihu.com/api/3/sections"
	resp := httplib.Get(hot_url)

	var v interface{}
	err := resp.ToJson(&v)
	if CheckErr(err) {
		return
	}
	c.Data["json"] = v
	c.ServeJson()
}
Ejemplo n.º 22
0
// @router /scom [get]
func (c *NewsController) ShortCom() {
	hot_url := "http://news-at.zhihu.com/api/4/story/4232852/short-comments"
	resp := httplib.Get(hot_url)

	var v interface{}
	err := resp.ToJson(&v)
	if CheckErr(err) {
		return
	}
	c.Data["json"] = v
	c.ServeJson()
}
Ejemplo n.º 23
0
// @router /story [get]
func (c *NewsController) Story() {
	hot_url := "http://news-at.zhihu.com/api/4/story-extra/3876052"
	resp := httplib.Get(hot_url)

	var v interface{}
	err := resp.ToJson(&v)
	if CheckErr(err) {
		return
	}
	c.Data["json"] = v
	c.ServeJson()
}
Ejemplo n.º 24
0
// @Title GMaps
// @Description gets GMaps API
// @Success 200 Maps retrieved
// @Failure 403 Connection or Proxy error
// @router /gmaps [get]
func (o *ObjectController) GMaps() {
	var maps models.Maps
	req := httplib.Get("https://maps.googleapis.com/maps/api/directions/json?origin=Lucknow&destination=Varanasi&key=AIzaSyDVYEzlC_MuzKNDIwWzipvny3dkf4nSBVo")
	req.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
	err := req.ToJSON(&maps)
	if err == nil {
		o.Data["json"] = maps
	} else {
		o.Data["json"] = err
	}
	o.ServeJSON()
}
Ejemplo n.º 25
0
// 	Amount   float32 //
// 	Vol      int32   //gu
// 	Reserved int32
// }
func (this *IndexController) Stock() {
	fmt.Println("In GetStock()...")
	req := httplib.Get("http://xueqiu.com/S/SH601166/historical.csv")
	str, err := req.String()
	if err != nil {
		fmt.Println(err.Error())
	}

	// days := make([]models.StockDay, 0)
	var days []interface{}
	lines := strings.Split(str, "\n")
	fmt.Println(len(lines))
	// for i := 1; i < len(lines); i++ {
	for i := 1; i < 100; i++ {
		column := strings.Split(lines[i], ",")
		// fmt.Println(i)
		// fmt.Println(len(column))
		if len(column) > 1 {
			// temp := new(models.StockDay)
			var temp models.StockDay

			temp.Code = column[0]

			// t := time.Parse("2014-08-07", column[1])
			// temp.Data = t.
			temp.Date = column[1]

			// f, _ := strconv.ParseFloat(column[2], 8)
			// temp.Open = float32(f)
			// fmt.Println(temp.Open)
			// f, _ = strconv.ParseFloat(column[3], 2)
			// temp.High = float32(f)
			// f, _ = strconv.ParseFloat(column[4], 2)
			// temp.Low = float32(f)
			// f, _ = strconv.ParseFloat(column[5], 2)
			// temp.Close = float32(f)

			temp.Open = column[2]
			temp.High = column[3]
			temp.Low = column[4]
			temp.Close = column[5]

			// i, _ = strconv.Atoi(column[6])
			// temp.Vol = int32(i)

			days = append(days, temp)
		}
	}

	this.Data["json"] = &days
	this.ServeJson()
}
Ejemplo n.º 26
0
Archivo: newsc.go Proyecto: shaalx/news
func (c *NewsVController) shortCom() interface{} {
	id := c.Ctx.Input.Param(":id")
	hot_url := fmt.Sprintf("http://news-at.zhihu.com/api/4/story/%s/short-comments", id)
	// hot_url := "http://news-at.zhihu.com/api/4/story/4232852/short-comments"
	resp := httplib.Get(hot_url)

	var v interface{}
	err := resp.ToJson(&v)
	if CheckErr(err) {
		return nil
	}
	return v
}
Ejemplo n.º 27
0
/* 判断token对应的id是否合法 */
func BaiduSocialCheck(token string, id string) bool {
	var r = struct {
		Id uint `json:"social_uid"`
	}{}
	err := httplib.Get("https://openapi.baidu.com/social/api/2.0/user/info").Param("access_token", token).SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}).ToJson(&r)
	if err != nil { //请求发送失败
		return false
	}
	if strconv.Itoa(int(r.Id)) != id { //id不符
		return false
	}
	return true
}
Ejemplo n.º 28
0
Archivo: newsc.go Proyecto: shaalx/news
// @router /latest [get]
func (c *NewsVController) VLatest() {
	hot_url := "http://news-at.zhihu.com/api/3/news/latest"
	resp := httplib.Get(hot_url)

	var v interface{}
	err := resp.ToJson(&v)
	if CheckErr(err) {
		return
	}
	c.Data["title"] = "Latest"
	c.Data["content"] = v
	c.TplNames = "latest.html"
}
Ejemplo n.º 29
0
Archivo: newsc.go Proyecto: shaalx/news
// @router /themes [get]
func (c *NewsVController) Themes() {
	hot_url := "http://news-at.zhihu.com/api/4/themes"
	resp := httplib.Get(hot_url)

	var v interface{}
	err := resp.ToJson(&v)
	if CheckErr(err) {
		return
	}
	c.Data["content"] = v
	c.Data["title"] = "Themes"
	c.TplNames = "themes.html"
}
Ejemplo n.º 30
0
func (this *Action) httpClientTest() {
	req := httplib.Get("http://www.baidu.com/")
	str, err := req.String()
	if err != nil {
		Error(err)
	}
	Debug(len(str))
	str, err = httplib.Post("http://www.baidu.com/").SetTimeout(100*time.Second, 30*time.Second).Param("wd", "go").String()
	if err != nil {
		Error(err)
	}
	Debug(len(str))
}