change this function to golang def freesubscribe(self, courseid: str): self.client.get(…
- User
change this function to golang def free_subscribe(self, courseid: str):
self.client.get( "https://www.udemy.com/course/subscribe/?courseId=" + courseid, verify=False, ) r = self.client.get( "https://www.udemy.com/api-2.0/users/me/subscribed-courses/" + courseid + "/?fields%5Bcourse%5D=%40default%2Cbuyable_object_type%2Cprimary_subcategory%2Cis_private", verify=False, ).json() try: if r["_class"] == "course": return True except: return False - Assistant
func free_subscribe(courseid string) bool { response1, err := http.Get("https://www.udemy.com/course/subscribe/?courseId=" + courseid)
if err != nil { fmt.Println(err) } defer response1.Body.Close() response2, err := http.Get("https://www.udemy.com/api-2.0/users/me/subscribed-courses/" + courseid + "/?fields%5Bcourse%5D=%40default%2Cbuyable_object_type%2Cprimary_subcategory%2Cis_private") if err != nil { fmt.Println(err) } defer response2.Body.Close() var r map[string]interface{} json.NewDecoder(response2.Body).Decode(&r) if r["_class"] == "course" { return true } else { return false }}
- User
Can you convert this function to golang def free_checkout(self, coupon: str, courseid: int): payload = { "checkout_environment": "Marketplace", "checkout_event": "Submit", "shopping_info": { "items": [ { "discountInfo": {"code": coupon}, "buyable": {"type": "course", "id": courseid}, "price": {"amount": 0, "currency": self.currency.upper()}, } ] }, "payment_info": { "method_id": "0", "payment_vendor": "Free", "payment_method": "free-method", }, }
# payload = json.dumps(payload) r = self.client.post( "https://www.udemy.com/payment/checkout-submit/", json=payload, verify=False, ) try: r = r.json() except: return "retry" try: if r["status"] == "succeeded": return True elif r["status"] == "failed": return False else: print("404040404") except: return r["detail"] - Assistant
func free_checkout(coupon string, courseid int) interface{} { payload := map[string]interface{}{ "checkout_environment": "Marketplace", "checkout_event": "Submit", "shopping_info": map[string]interface{}{ "items": []map[string]interface{}{ { "discountInfo": map[string]interface{}{"code": coupon}, "buyable": map[string]interface{}{"type": "course", "id": courseid}, "price": map[string]interface{}{"amount": 0, "currency": strings.ToUpper(self.currency)}, }, }, }, "payment_info": map[string]interface{}{ "method_id": "0", "payment_vendor": "Free", "payment_method": "free-method", }, } jsonData, err := json.Marshal(payload) if err != nil { fmt.Println(err) } r, err := self.client.Post("https://www.udemy.com/payment/checkout-submit/", "application/json", bytes.NewBuffer(jsonData)) if err != nil { fmt.Println(err) }
var response interface{} err = json.NewDecoder(r.Body).Decode(&response) if err != nil { return "retry" } switch response.(type) { case map[string]interface{}: if response.(map[string]interface{})["status"] == "succeeded" { return true } else if response.(map[string]interface{})["status"] == "failed" { return false } } return response