Best Gauge code snippet using parser.getIndex
getlist.go
Source:getlist.go
1package webqq2import (3 "encoding/json"4 "fmt"5 "net/url"6 "strconv"7 . "webqq/tools"8 "webqq/tools/simplejson"9)10func init() {11 fmt.Print("")12}13type Friend struct {14 Uin string15 Categories int16 Nick string17 Markname string18 Face int19 Online int20 Id string21}22type FriendMap map[string]*Friend23type CataMap map[int]string24type FriendList struct {25 FriendMap26 CataMap27}28func (qq *Client) GetFriendList() (flst *FriendList, err error) {29 defer func() {30 if e := recover(); e != nil {31 err = e.(error)32 }33 }()34 v := url.Values{}35 h, err := json.Marshal(36 map[string]string{37 `h`: `hello`,38 `vfwebqq`: qq.vfwebqq,39 `hash`: hash(qq.id, qq.ptwebqq)})40 v.Set(`r`, string(h))41 re, err := qq.postForm(`http://s.web2.qq.com/api/get_user_friends2`, v)42 if err != nil {43 panic(err)44 }45 defer re.Body.Close()46 flst, err = friendListParser(ReadByte(re.Body))47 if err != nil {48 panic(err)49 }50 for i := range flst.FriendMap {51 va, err := qq.GetId(i)52 if err != nil {53 panic(err)54 }55 flst.FriendMap[i].Id = va56 }57 return58}59func friendListParser(in []byte) (f *FriendList, err error) {60 js, err := simplejson.NewJson(in)61 if err != nil {62 return nil, err63 }64 f = &FriendList{}65 f.FriendMap = make(FriendMap)66 f.CataMap = make(CataMap)67 result := js.Get(`result`)68 for i, cat := 0, result.Get(`categories`); i < len(cat.MustArray()); i++ {69 f.CataMap[cat.GetIndex(i).Get(`index`).MustInt()] = cat.GetIndex(i).Get(`name`).MustString()70 }71 for i, frd := 0, result.Get(`friends`); i < len(frd.MustArray()); i++ {72 uin := fmt.Sprint(int64(frd.GetIndex(i).Get(`uin`).MustFloat64()))73 categories := frd.GetIndex(i).Get(`categories`).MustInt()74 f.FriendMap[uin] = &Friend{Uin: uin, Categories: categories}75 }76 for i, inf := 0, result.Get(`info`); i < len(inf.MustArray()); i++ {77 uin := fmt.Sprint(int64(inf.GetIndex(i).Get(`uin`).MustFloat64()))78 nick := inf.GetIndex(i).Get(`nick`).MustString()79 face := inf.GetIndex(i).Get(`face`).MustInt()80 flag := inf.GetIndex(i).Get(`flag`).MustInt()81 if ptr, ok := f.FriendMap[uin]; ok {82 ptr.Nick = nick83 ptr.Markname = nick84 ptr.Face = face85 ptr.Online = flag86 }87 }88 for i, mkn := 0, result.Get(`marknames`); i < len(mkn.MustArray()); i++ {89 markname := mkn.GetIndex(i).Get(`markname`).MustString()90 uin := fmt.Sprint(int64(mkn.GetIndex(i).Get(`uin`).MustFloat64()))91 if ptr, ok := f.FriendMap[uin]; ok {92 ptr.Markname = markname93 }94 }95 return96}97type b struct {98 s, e int99}100func nb(c, i int) b {101 return b{s: c | 0, e: i | 0}102}103func hash(is, a string) string {104 r := [4]int{}105 i, _ := strconv.Atoi(is)106 r[0] = i >> 24 & 255107 r[1] = i >> 16 & 255108 r[2] = i >> 8 & 255109 r[3] = i >> 0 & 255110 j := []int{}111 for e := 0; e < len(a); e++ {112 j = append(j, int(a[e]))113 }114 e := []b{}115 for e = append(e, nb(0, len(j)-1)); len(e) > 0; {116 var c = e[len(e)-1]117 e = e[:len(e)-1]118 if !(c.s >= c.e || c.s < 0 || c.e >= len(j)) {119 if c.s+1 == c.e {120 if j[c.s] > j[c.e] {121 j[c.s], j[c.e] = j[c.e], j[c.s]122 }123 } else {124 var f = j[c.s]125 var l = c.s126 var J = c.e127 for c.s < c.e {128 for c.s < c.e && j[c.e] >= f {129 c.e--130 r[0] = (r[0] + 3) & 255131 }132 if c.s < c.e {133 j[c.s] = j[c.e]134 c.s++135 r[1] = (r[1]*13 + 43) & 255136 }137 for c.s < c.e && j[c.s] <= f {138 c.s++139 r[2] = (r[2] - 3) & 255140 }141 if c.s < c.e {142 j[c.e] = j[c.s]143 c.e--144 r[3] = (r[0] ^ r[1] ^ r[2] ^ (r[3] + 1)) & 255145 }146 }147 j[c.s] = f148 e = append(e, nb(l, c.s-1))149 e = append(e, nb(c.s+1, J))150 }151 }152 }153 js := []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}154 es := ""155 for c := 0; c < len(r); c++ {156 es += js[r[c]>>4&15]157 es += js[r[c]&15]158 }159 return es160}161/*162{163 "retcode": 0,164 "result": {165 "friends": [166 {167 "flag": 0,168 "uin": 1192173647,169 "categories": 0170 },171 {172 "flag": 4,173 "uin": 2549892970,174 "categories": 1175 },176 {177 "flag": 0,178 "uin": 4069820047,179 "categories": 0180 },181 {182 "flag": 0,183 "uin": 490067261,184 "categories": 0185 },186 {187 "flag": 0,188 "uin": 4185452572,189 "categories": 0190 },191 {192 "flag": 8,193 "uin": 223290852,194 "categories": 2195 },196 {197 "flag": 8,198 "uin": 1196002108,199 "categories": 2200 }201 ],202 "marknames": [203 {204 "uin": 223290852,205 "markname": "æ²è¶
",206 "type": 0207 },208 {209 "uin": 1196002108,210 "markname": "大头",211 "type": 0212 }213 ],214 "categories": [215 {216 "index": 1,217 "sort": 1,218 "name": "éå"219 },220 {221 "index": 2,222 "sort": 2,223 "name": "åå¦"224 }225 ],226 "vipinfo": [227 {228 "vip_level": 0,229 "u": 1192173647,230 "is_vip": 0231 },232 {233 "vip_level": 0,234 "u": 2549892970,235 "is_vip": 0236 },237 {238 "vip_level": 2,239 "u": 4069820047,240 "is_vip": 1241 },242 {243 "vip_level": 0,244 "u": 490067261,245 "is_vip": 0246 },247 {248 "vip_level": 0,249 "u": 4185452572,250 "is_vip": 0251 },252 {253 "vip_level": 0,254 "u": 223290852,255 "is_vip": 0256 },257 {258 "vip_level": 0,259 "u": 1196002108,260 "is_vip": 0261 }262 ],263 "info": [264 {265 "face": 600,266 "flag": 29884928,267 "nick": "42",268 "uin": 1192173647269 },270 {271 "face": 12,272 "flag": 0,273 "nick": "ç«éæ ½è²",274 "uin": 2549892970275 },276 {277 "face": 0,278 "flag": 13107718,279 "nick": "æé",280 "uin": 4069820047281 },282 {283 "face": 336,284 "flag": 13107712,285 "nick": "度竹轻衣",286 "uin": 490067261287 },288 {289 "face": 558,290 "flag": 524802,291 "nick": "Qrox",292 "uin": 4185452572293 },294 {295 "face": 339,296 "flag": 13140480,297 "nick": "å¼å¼å¼å»¿å
å",298 "uin": 223290852299 },300 {301 "face": 147,302 "flag": 8388608,303 "nick": "blue~beak",304 "uin": 1196002108305 }306 ]307 }308}*/...
resolve.go
Source:resolve.go
1package resolve2import (3 "fmt"4 "parser"5 "maths_functions"6 "types"7 "strings"8 "strconv"9 "equations"10 "maps"11 "replace_vars"12)13type Unknown struct {14 Tab map[int]string15 Deg_max map[int]int16 Part1 map[int]string17 Part2 map[int]string18 Eqs map[int]equations.Equation19}20type Resol struct {21 Tab map[int]string22}23func IsSoluble(U Unknown) (bool) {24 for i := 0; i < len(U.Deg_max); i++ {25 if U.Deg_max[i] > 2 || U.Deg_max[i] < 0 {26 return (false)27 }28 }29 return (true)30}31func Init(U *Unknown, Dat types.Variable) (string) {32 res, t := getSignEq(U)33 if res == "1" {34 if t == 2 {35 ModMAps(U)36 RempEq(U.Tab, U, Dat)37 return ("|")38 }39 if t == 1 {40 return ("Sorry i Cant resolve this equation")41 }42 RempEq(U.Tab, U, Dat)43 return ("|")44 }45 return (res)46}47func ModMAps(U *Unknown) {48 A := Unknown{}49 tmp := make(map[int]string)50 tmp1 := make(map[int]string)51 tmp[0] = U.Part1[0]52 A.Part1 = tmp53 tmp1[0] = U.Part2[0]54 A.Part2 = tmp155 A.Tab = make(map[int]string)56 A.Tab[0] = U.Tab[0]57 A.Tab[1] = "0"58 A.Deg_max = make(map[int]int)59 A.Deg_max[0] = U.Deg_max[0]60 A.Deg_max[1] = 061 U = &A62}63func getSignEq(U *Unknown) (string, int) {64 if len(U.Part1) > 2 {65 66 sign := InitSign(U.Part1[1])67 if sign == "%" {68 return "Sorry i can't resolve this equation", 069 }70 for i := 3; i < len(U.Part1); i += 2 {71 fmt.Println(U.Part1[i])72 if strings.Index(sign, U.Part1[i]) == -1 {73 return "Sorry i can't resolve this equation", 074 }75 }76 if len(sign) == 1 && (len(U.Part2) > 2 || (U.Part2[0] != "0" && U.Part2[0] != "-0")) {77 return "Sorry i can't resolve this equation", 078 }79 if sign == "*" {80 return "1", 181 }82 if sign == "/" {83 return "1", 284 }85 }86 for a := 0; a < len(U.Tab); a++ {87 if strings.Index(U.Tab[a], "(") != -1 || strings.Index(U.Tab[a], ")") != -1 || strings.Index(U.Tab[a], "[") != -1 || strings.Index(U.Tab[a], "]") != -1 || strings.Index(U.Tab[a], "i") != -1 {88 return "Sorry i can't resolve this equation", 089 }90 }91 return "1", 392}93func InitSign(str string) (string) {94 if str == "+" || str == "-" {95 return ("+-")96 }97 return (str)98}99func RempEq(tab map[int]string, U *Unknown, Dat types.Variable) {100 WE := 0101 pos_s := -3102 var sign string103 for i := 0; i < len(tab); i++ {104 tab[i] = strings.ReplaceAll(tab[i], " ", "")105 if (len(U.Part1) - 1) / 2 < i {106 WE = 1107 pos_s = -3108 }109 pos_s += 2110 if WE == 1 && i - 1 >= 0 {111 fmt.Printf("2\n")112 sign = U.Part2[pos_s]113 } else if WE == 0 && i - 1 >= 0 {114 fmt.Printf("1\n")115 sign = U.Part1[pos_s]116 }117 if strings.Index(tab[i], "|") != -1 {118 e := strings.Split(tab[i], "|")119 ck := 0120 GetAllSign(maps.Join(parser.Checkfunc(parser.GetAllIma(e[0], &ck), Dat), ""), e[1], U, WE, sign, Dat)121 } else {122 RPuis(tab[i], 0, WE, U, sign, Dat)123 }124 }125}126func GetAllSign(str string, x string, U *Unknown, WE int, signdeb string, Dat types.Variable) {127 var puis int128 var sign int129 if str[0] == '-' || str[0] == '+' {130 if str[0] == '-' {131 sign = 1132 }133 str = str[1:len(str)]134 }135 for i := GetIndex(str); i != -1; i = GetIndex(str) {136 if str[0] == '-' || str[0] == '+' {137 if str[0] == '-' {138 sign = 1139 }140 str = str[1:len(str)]141 i = GetIndex(str)142 if i == -1 {143 break144 }145 }146 puis = GetMaxDeg(str[0:i], x)147 if puis < 0 {148 puis = 0149 }150 if sign == 1 {151 RPuis(getNumber("-" + str[0:i], x), puis, WE, U, signdeb, Dat)152 } else {153 RPuis(getNumber(str[0:i], x), puis, WE, U, signdeb, Dat)154 }155 str = str[i:len(str)]156 sign = 0157 }158 puis = GetMaxDeg(str, x)159 if puis < 0 {160 puis = 0161 }162 RPuis(getNumber(str, x), puis, WE, U, signdeb, Dat)163}164func getNumber(str string, x string) (string) {165 if strings.Index(str, "Ë") != -1 || strings.Index(str, "^") != -1 {166 index := strings.Index(str, x)167 str = str[0:index]168 }169 str = strings.ReplaceAll(str, "*", "")170 str = strings.ReplaceAll(str, x, "")171 if str == "" {172 return ("1")173 }174 return (str)175}176func GetIndex(str string) (int) {177 max := -1178 a := strings.Index(str, "/")179 if a != -1 && (max == -1 || a < max) {180 max = a181 }182 a = strings.Index(str, "%")183 if a != -1 && (max == -1 || a < max) {184 max = a185 }186 a = strings.Index(str, "-")187 if a != -1 && (max == -1 || a < max) {188 max = a189 }190 a = strings.Index(str, "+")191 if a != -1 && (max == -1 || a < max) {192 max = a193 }194 return (max)195}196func RPuis(nb string, puis int, wEqs int, U *Unknown, sign string, Dat types.Variable) {197 var Eq equations.Equation198 if len(U.Eqs) == 0 {199 U.Eqs = make(map[int]equations.Equation)200 }201 if val, ok := U.Eqs[wEqs]; ok {202 Eq = val203 } else {204 Eq = equations.Equation{}205 }206 207 nb = replace_vars.GetVars(&Dat, nb)208 t1, _ := strconv.ParseFloat(nb, 64)209 210 if sign == "-" {211 if puis == 0 {212 Eq.C -= t1213 } else if puis == 1 {214 Eq.B -= t1215 } else if puis == 2 {216 Eq.A -= t1217 }218 } else if sign == "+" || sign == "" {219 if puis == 0 {220 Eq.C += t1221 } else if puis == 1 {222 Eq.B += t1223 } else if puis == 2 {224 Eq.A += t1225 }226 }227 U.Eqs[wEqs] = Eq228}229func IsEquation(U *Unknown, Dat types.Variable, t int) (bool) {230 231 var tab map[int]string232 if t == 0 {233 tab = U.Part1234 } else {235 tab = U.Part2236 }237 if len(U.Tab) == 0 {238 U.Tab = make(map[int]string)239 U.Deg_max = make(map[int]int)240 }241 f := 0242 for i := 0; i < len(tab); i += 2 {243 if parser.IsFunc(tab[i], 0) == 1 {244 x := maths_functions.Getx(tab[i])245 p1 := strings.Index(tab[i], "(")246 p2 := strings.Index(tab[i], ")")247 r := tab[i][p1 + 1:p2]248 if parser.IsExpression(x, r, Dat) {249 return (false)250 }251 _, val := parser.GetDataFunc(tab[i], Dat.Table)252 if val == "" {253 return (false)254 }255 U.Tab[len(U.Tab)] = val + "|" + x256 U.Deg_max[len(U.Deg_max)] = GetMaxDeg(val, x)257 f++258 } else {259 U.Tab[len(U.Tab)] = tab[i]260 U.Deg_max[len(U.Deg_max)] = 0261 f++262 }263 }264 if f == 0 {265 return (false)266 }267 return (true)268}269func GetMaxDeg(str string, x string) (int) {270 var z, i int271 str = strings.ReplaceAll(str, " ", "")272 a := strings.Index(str, x)273 if a == -1 {274 return (-3)275 }276 max := 1277 str = strings.ReplaceAll(str, "Ë", "^")278 for a = a; a != -1; a = strings.Index(str, x) {279 if a + 1 >= len(str) {280 return (max)281 }282 if str[a + 1] == '*' {283 z, i = GetDeg('*', str, a + 1, x)284 if z > max {285 max = z286 }287 } else if string(str[a + 1]) == "^" {288 z, _ = strconv.Atoi(string(str[a + 2]))289 i = a + 3290 if z > max {291 max = z292 }293 }294 if i + 1 >= len(str) {295 return (max)296 }297 str = str[i + 1:len(str)]298 }299 return (max)300}301func GetDeg(sign byte, str string, deb int, x string) (int, int) {302 puis := 1303 i := deb304 for i = i; i < len(str) && str[i] == sign; i += 2 {305 if string(str[i + 1]) == x {306 puis++307 }308 }309 return puis, i310}...
nationstatmanager.go
Source:nationstatmanager.go
1package nsmanager2import(3 "download/nsdownload"4 "parser/nsparser"5 ns "entity/nsentity"6 "manager"7 "util"8 "fmt"9 "strings"10 "time"11)12const(13 //NSStart = "198301"14 NSStart = "201401"15 NSEnd = "-1"16 NSDateFormat = "2006-01"17 NSInputDateFormat = "200601"18)19type NationStatManager struct {20 manager.ManagerBase21 downloader *nsdownload.NationStatDownloader22 parser *nsparser.NSParser23 idxmap map[string] []ns.NSDataIndex24 nsstart string //"yyyyMM" or "-1" as to present25 nsend string26}27func (m *NationStatManager) Init() {28 m.ManagerBase.Init()29 m.downloader = nsdownload.NewNationStatDownloader()30 m.parser = nsparser.NewNSParser()31 m.idxmap = make(map[string] []ns.NSDataIndex)32}33func (m *NationStatManager) Process() {34 datastr := m.downloader.GetRoot()35 if len(datastr) == 0 {36 m.Logger.Error("Cannot get the children of root")37 }38 m.WriteIndexData("root", 0, datastr)39 rootData := m.parser.ParseIndex(datastr)40 m.OutputIndex(rootData)41 for _, root := range rootData {42 if root.IsParent {43 m.GetIndex(root, 1)44 }45 }46 m.WriteIndex()47}48func (m *NationStatManager) GetIndex(idxdata ns.NSIndex, level int) {49 datastr := m.downloader.GetChild(idxdata.Id, level)50 if len(datastr) == 0 {51 m.Logger.Error("Cannot get the children of:", idxdata.Id, " in level: ", level)52 }53 m.WriteIndexData(idxdata.Id, level, datastr)54 idxchild := m.parser.ParseIndex(datastr)55 dataid := make([]string, 0)56 for _, idx := range idxchild {57 if idx.IfData == "1" {58 dataid = append(dataid, idx.Id)59 } else if idx.IsParent || idx.IfData == "4" {60 m.GetIndex(idx, level + 1)61 } else {62 //do nothing63 }64 }65 66 if len(dataid) > 0 {67 m.GetData(idxdata.Id, dataid, m.nsstart, m.nsend)68 }69}70func (m *NationStatManager) GetData(pid string, ids []string, start string, end string) {71 datastr := m.downloader.GetData(ids, start, end)72 if len(datastr) == 0 {73 m.Logger.Error("Cannot get data of: ", ids, start, end)74 }75 m.WriteData(ids, start, end, datastr)76 nsvalue := m.parser.ParseData(datastr)77 m.WriteValue(ids, start, end, nsvalue.TableData)78 m.AddIndex(pid, nsvalue.Value.Index)79}80func (m *NationStatManager) AddIndex(pid string, indexes []ns.NSDataIndex) {81 values, ok := m.idxmap[pid]82 if !ok {83 m.idxmap[pid] = indexes84 } else {85 values = append(values, indexes ...)86 m.idxmap[pid] = values87 }88}89func (m *NationStatManager) WriteIndexData(id string, level int, content string) {90 format := "%sdata/ns/index-%v-%v.dat"91 filename := fmt.Sprintf(format, m.BaseDir, level, id)92 fmt.Println(filename)93 util.WriteFile(filename, content)94}95func (m *NationStatManager) WriteData(ids []string, start, end, content string) {96 idstr := strings.Join(ids, "-")97 format := "%sdata/ns/data-%v-%v-%v.dat"98 filename := fmt.Sprintf(format, m.BaseDir, ids[0], start, end)99 content += idstr + "\n" + content100 util.WriteFile(filename, content)101}102func (m *NationStatManager) WriteValue(ids []string, start string, end string, data map[string]string) {103 idstr := strings.Join(ids, "-")104 format := "%sdata/ns/actualdata-%v-%v-%v.dat"105 filename := fmt.Sprintf(format, m.BaseDir, ids[0], start, end)106 content := idstr + "\n"107 for k, v := range data{108 content += k + ": " + v + "\n"109 }110 util.WriteFile(filename, content)111}112func (m *NationStatManager) WriteIndex() {113 format := "%sdata/ns/macroindex.dat"114 filename := fmt.Sprintf(format, m.BaseDir)115 var content string116 for k, vs := range m.idxmap {117 content += fmt.Sprintf("=============Parent: %v\n", k)118 for _, v := range vs {119 content += fmt.Sprintf("%v: %v\n", v.Id, v.Name)120 }121 }122 util.WriteFile(filename, content)123}124func (m *NationStatManager) OutputIndex(idxdata []ns.NSIndex){125 var str string126 for _, v := range idxdata {127 str += fmt.Sprintf("Id: %v, Name: %v, PId: %v, EName: %v, IfData: %v, IsParent: %v\n", v.Id, v.Name, v.PId, v.EName, v.IfData, v.IsParent)128 //fmt.Println(str)129 130 }131 m.Logger.Info(str)132}133func NewNationStatManager(start, end string) *NationStatManager{134 m := new(NationStatManager)135 m.Init()136 137 t, err := time.Parse(NSDateFormat, start)138 if err != nil {139 m.nsstart = "-1"140 } else {141 m.nsstart = t.Format(NSInputDateFormat)142 }143 t, err = time.Parse(NSDateFormat, end)144 if err != nil {145 m.nsend = "-1"146 } else {147 m.nsend = t.Format(NSInputDateFormat)148 }149 fmt.Println("start: ", m.nsstart, " end: ", m.nsend)150 return m151}...
getIndex
Using AI Code Generation
1import (2func main() {3 fmt.Println(parser.getIndex())4}5func getIndex() int {6}7 /usr/local/go/src/parser (from $GOROOT)8 /home/username/go/src/parser (from $GOPATH)
getIndex
Using AI Code Generation
1import (2func main() {3 parser := parser.Parser{Data: "mydata"}4 fmt.Println(parser.GetIndex())5}6import (7func main() {8 parser := parser.Parser{Data: "mydata"}9 fmt.Println(parser.GetIndex())10}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!