Skip to content

Instantly share code, notes, and snippets.

@ariankordi
Last active September 10, 2018 22:55
Show Gist options
  • Save ariankordi/cb7ed9cb1a0b61c9fc326bb265ea1434 to your computer and use it in GitHub Desktop.
Save ariankordi/cb7ed9cb1a0b61c9fc326bb265ea1434 to your computer and use it in GitHub Desktop.
A little Go script that gets the AdSense revenue you have this month
package main
import (
"github.com/valyala/fasthttp"
"bytes"
"fmt"
)
var req = fasthttp.AcquireRequest()
var resp = fasthttp.AcquireResponse()
var client = &fasthttp.Client{}
//const cookie = "Paste the cookie you see when going to AdSense here, you have to uncomment this const"
func main() {
req.Header.SetMethod("POST")
req.Header.Add("Client-Version", "44084f1953159cf725c5620637189f1689d48d6f")
req.Header.Add("X-Lightfe-Auth", "1")
req.Header.Add("Cookie", cookie)
req.SetRequestURI("https://www.google.com/adsense/m/data/home")
client.Do(req, resp)
thisMonthPart1 := bytes.Split(resp.Body(), []byte("month "))[1]
thisMonthPart2 := bytes.Split(thisMonthPart1, []byte("$"))[1]
thisMonthPart3 := bytes.Split(thisMonthPart2, []byte("\""))[0]
fmt.Println(string(thisMonthPart3))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment