def send_message(request): bot = telegram.Bot(token=settings.TOKEN) udemy = Udemy(settings.CLIENT_ID, settings.CLIENT_SECRET) course = udemy.courses(page=1, page_size=1, category='Development', price='price-free', ordering='newest') kwargs = { 'identifier': course['results'][0]['id'], 'title': course['results'][0]['title'], 'url': course['results'][0]['url'], 'image_240x135': course['results'][0]['image_240x135'], 'image_480x270': course['results'][0]['image_480x270'] } if not Course.objects.filter(identifier=kwargs.get('identifier')): course = create_course(**kwargs) bot.send_message(chat_id="@udemy_free_courses", text=message(course), parse_mode=telegram.ParseMode.HTML) return HttpResponse()
def create_course(): udemy = Udemy(settings.UDEMY_CLIENT_ID, settings.UDEMY_CLIENT_SECRET) course = udemy.courses(page=1, page_size=1, category='Development', price='price-free', ordering='newest') kwargs = { 'identifier': course['results'][0]['id'], 'title': course['results'][0]['title'], 'url': course['results'][0]['url'], 'image_240x135': course['results'][0]['image_240x135'], 'image_480x270': course['results'][0]['image_480x270'] } course, _ = Course.objects.get_or_create(**kwargs) return course
from pyudemy import Udemy client = Udemy( "Z4iHcLBb8gtAv1lKRnW7fley2jwqkb9Ws6yBDd9x", "wjkd2mWGAhU9A2lIMVrHhMVOdB5Wz9QOtyFfhBQVrD5EcLVjNEGpdiEIQD4PNuuX1d7pprgbdtugtQmUwExLQzudkZxRDvTDPpAC6kYlOPMizrcVq9JyLJXQRXTotBvO" ) course = client.courses(page=1, page_size=5, search='machine learning') course_detail = client.course_detail(id='1968412') course_review = client.course_reviews('950390') for review in course_review['results']: print(review['content'])
from pyudemy import Udemy from pymongo import * import pprint udemy = Udemy('', '') def fetch_data(search_for): search_term = search_for instrution_levels = ['beginner', 'intermediate', 'expert'] mng_client = MongoClient('localhost', 27017) db = mng_client.arjun for x in range(0, len(instrution_levels)): response = udemy.courses(page=1, page_size=20, search=search_term, ordering='highest-rated', ratings='3', instructional_level=instrution_levels[x]) #[--------------------- COURSE DETAILS LOOP --------------------------] for i in range(0, len(response['results'])): result = {'course_level': x + 1} courseCir = udemy.public_curriculum(response['results'][i]['id']) courseRew = udemy.course_reviews(response['results'][i]['id']) result['course_source'] = 'udemy' result['search_term'] = search_term result['course_title'] = response['results'][i]['title'] result['course_link'] = 'https://www.udemy.com' + str( response['results'][i]['url'])
sys.path.insert(0, os.getcwd()) import requests import json from typing import Any, Dict, List import logging from urllib import parse from pyudemy import Udemy import requests from bs4 import BeautifulSoup from typing import Dict, Any, Union, List udemy = Udemy(config.CLIENT_ID, config.CLIENT_SECRET) def get_courses(content, bot_handler: Any) -> str: courses = udemy.courses() print(courses) res = "" i = 1 for course in courses['results']: res = res + course['title'] + "\n" + "https://www.udemy.com" + course[ 'url'] + "\n" + course['price'] + "\n\n" i += 1 if i == 5:
def setUp(self): self.client_id = "client_id" self.client_secret = "client_secret" self.udemy = Udemy(self.client_id, self.client_secret)
class UdemyTestCase(unittest.TestCase): def setUp(self): self.client_id = "client_id" self.client_secret = "client_secret" self.udemy = Udemy(self.client_id, self.client_secret) def test_get_url(self): self.assertEqual( self.udemy._get_url("courses"), "https://www.udemy.com/api-2.0/courses/?" ) self.assertEqual( self.udemy._get_url("courses", page=1, page_size=1, search="javascript"), "https://www.udemy.com/api-2.0/courses/?page=1&page_size=1&search=javascript&", ) def test_authentication(self): self.assertEqual(self.udemy._authentication.username, self.client_id) self.assertEqual(self.udemy._authentication.password, self.client_secret) @requests_mock.Mocker() def test_courses(self, request_mock): url = "https://www.udemy.com/api-2.0/courses/" request_mock.get(url, json=COURSES) self.assertEqual(self.udemy.courses(), COURSES) @requests_mock.Mocker() def test_courses_with_kwargs(self, request_mock): url = "https://www.udemy.com/api-2.0/courses/?page=1&page_size=1" kwargs = { "page": 1, "page_size": 1, } request_mock.get(url, json=COURSES_WITH_PARAMS) self.assertEqual(self.udemy.courses(**kwargs), COURSES_WITH_PARAMS) @requests_mock.Mocker() def test_courses_detail(self, requests_mock): url = "https://www.udemy.com/api-2.0/courses/12345/" requests_mock.get(url, json=COURSE_DETAIL) self.assertEqual(self.udemy.course_detail(12345), COURSE_DETAIL) @requests_mock.Mocker() def test_public_curriculum(self, requests_mock): url = "https://www.udemy.com/api-2.0/courses/12345/public-curriculum-items/" requests_mock.get(url, json=PUBLIC_CURRICULUM) self.assertEqual(self.udemy.public_curriculum(12345), PUBLIC_CURRICULUM) @requests_mock.Mocker() def test_public_curriculum_with_kwargs(self, requests_mock): url = "https://www.udemy.com/api-2.0/courses/12345/public-curriculum-items/" kwargs = {"page": 1, "page_size": 1} requests_mock.get(url, json=PUBLIC_CURRICULUM_WITH_PARAMS) self.assertEqual( self.udemy.public_curriculum(12345, **kwargs), PUBLIC_CURRICULUM_WITH_PARAMS ) @requests_mock.Mocker() def test_course_reviews(self, request_mock): url = "https://www.udemy.com/api-2.0/courses/12345/reviews/" request_mock.get(url, json=COURSE_REVIEWS) self.assertEqual(self.udemy.course_reviews(12345), COURSE_REVIEWS) @requests_mock.Mocker() def test_course_reviews_with_kwargs(self, request_mock): url = "https://www.udemy.com/api-2.0/courses/12345/reviews/?page=1&page_size=1" kwargs = {"page": 1, "page_size": 1} request_mock.get(url, json=COURSES_REVIEWS_WITH_PARAMS) self.assertEqual( self.udemy.course_reviews(12345, **kwargs), COURSES_REVIEWS_WITH_PARAMS )
from pyudemy import Udemy from decouple import config client_id = config('CLIENT_ID') client_secret = config('CLIENT_SECRET') udemy = Udemy(client_id, client_secret) print(udemy.courses())
import os client_id=os.environ.get('udemy_client_id') client_secret=os.environ.get('udemy_client_secret') from pyudemy import Udemy udemy=Udemy(client_id,client_secret) courslist=udemy.courses(page=1,page_size=10) courseID=udemy.course_detail(362328) #kurs ıd si with open('udemy_courses.csv','w') as f: f.write('ID,TİTLE,PRICE,URL\n') for k in courselist['results']: f.write("%s,%s,%s,%s\n"%(k["id"],k["title"],k["price"][1:],k["url"])) import csv with open('udemy_courses.csv','w',newline='') as file: writer=csv.writer(file) writer.writerow(["ID","TITLE","PRICE","URL"]) for key in courslist['results']: tlist=[key["id"],key["title"],key["price"][1:],key["url"]] writer.writerow(tlist)
"url"] = "https://www.udemy.com" + course["url"] courses_for_profession[skill][ course["title"]]["price"] = course["price"] courses_for_profession[skill][course["title"]][ "image_240x135"] = course["image_240x135"] with open(os.path.join(os.getcwd(), 'udemy_courses_for_profession' + '.json'), "w", encoding="utf-8") as f: json.dump(courses_for_profession, f, indent=4) print("key2", len(courses_for_profession.keys())) if __name__ == '__main__': client_id = 'XGwKUxLDixGf4mD9UHJNCPLXD9vzVfM6NA9YKufa' client_secret = 'gYeTjrLot8ndRDdGyBwe1dx3SEVzrwVmAzOpxieZWZOqPYXwGpt6dWmd5xWZ1L7Rxazec5o25' \ 'LANhkgByzsm3J0XtQJxPFpMHJRpzMUb7fFAXidW2hYygnebyO67X83L' udemy = Udemy(client_id, client_secret) courses = udemy.courses() with open(os.path.join(os.getcwd(), 'udemy_courses' + '.json'), "w", encoding="utf-8") as f: json.dump(courses, f, indent=4) skill_list = ["AWS Machine Learning", "design", "Gamification"] find1_course_for_skill(courses, skill_list)
from pyudemy import Udemy import json import random import time try: from .get_more_info import get_more_info except ImportError: from get_more_info import get_more_info CLIENT_ID = 'XGwKUxLDixGf4mD9UHJNCPLXD9vzVfM6NA9YKufa' CLIENT_SECRET = 'gYeTjrLot8ndRDdGyBwe1dx3SEVzrwVmAzOpxieZWZOqPYXwGpt6dWmd5xWZ1L7Rxazec5o25' \ 'LANhkgByzsm3J0XtQJxPFpMHJRpzMUb7fFAXidW2hYygnebyO67X83L' UDEMY = Udemy(CLIENT_ID, CLIENT_SECRET) def generate_result(max_page=999999999): """ Main function, that generates udemy_results.json file :param max_page: number of pages to search """ current_page = 1 while current_page <= max_page: # getting result dictionary result = json.load(open("udemy_results.json", 'r')) # getting information from API current_courses_info = UDEMY.courses(page=current_page) print(f"Number of requests: {current_page}")
def setUp(self): self.client_id = config('CLIENT_ID') self.client_secret = config('CLIENT_SECRET') self.udemy = Udemy(self.client_id, self.client_secret)
class UdemyTestCase(unittest.TestCase): def setUp(self): self.client_id = config('CLIENT_ID') self.client_secret = config('CLIENT_SECRET') self.udemy = Udemy(self.client_id, self.client_secret) def test_get_url(self): self.assertEqual(self.udemy._get_url('courses'), 'https://www.udemy.com/api-2.0/courses/?') self.assertEqual( self.udemy._get_url('courses', page=1, page_size=1, search='javascript'), 'https://www.udemy.com/api-2.0/courses/?page=1&page_size=1&search=javascript&' ) def test_authentication(self): self.assertEqual(self.udemy._authentication.username, self.client_id) self.assertEqual(self.udemy._authentication.password, self.client_secret) @requests_mock.Mocker() def test_courses(self, request_mock): url = 'https://www.udemy.com/api-2.0/courses/' data = { 'course': 'Test Course', } request_mock.get(url, json=data) self.assertEqual(self.udemy.courses(), data) @requests_mock.Mocker() def test_courses_with_kwargs(self, request_mock): url = 'https://www.udemy.com/api-2.0/courses/?page=1&page_size=1' kwargs = { 'page': 1, 'page_size': 1, } data = { 'course': 'Test Course', } request_mock.get(url, json=data) self.assertEqual(self.udemy.courses(**kwargs), data) @requests_mock.Mocker() def test_courses_detail(self, requests_mock): url = 'https://www.udemy.com/api-2.0/courses/12345/' data = { 'course': 'Test Course', } requests_mock.get(url, json=data) self.assertEqual(self.udemy.course_detail(12345), data) @requests_mock.Mocker() def test_public_curriculum(self, requests_mock): url = 'https://www.udemy.com/api-2.0/courses/12345/public-curriculum-items/' data = { 'public_curriculum': 'Public Curriculum', } requests_mock.get(url, json=data) self.assertEqual(self.udemy.public_curriculum(12345), data) @requests_mock.Mocker() def test_public_curriculum_with_kwargs(self, requests_mock): url = 'https://www.udemy.com/api-2.0/courses/12345/public-curriculum-items/' kwargs = {'page': 1, 'page_size': 1} data = { 'public_curriculum': 'Public Curriculum', } requests_mock.get(url, json=data) self.assertEqual(self.udemy.public_curriculum(12345, **kwargs), data) @requests_mock.Mocker() def test_course_reviews(self, request_mock): url = 'https://www.udemy.com/api-2.0/courses/12345/reviews/' data = { 'review': 'Test Review', } request_mock.get(url, json=data) self.assertEqual(self.udemy.course_reviews(12345), data) @requests_mock.Mocker() def test_course_reviews_with_kwargs(self, request_mock): url = 'https://www.udemy.com/api-2.0/courses/12345/reviews/?page=1&page_size=1' kwargs = {'page': 1, 'page_size': 1} data = { 'review': 'Test Review', } request_mock.get(url, json=data) self.assertEqual(self.udemy.course_reviews(12345, **kwargs), data)
from pyudemy import Udemy client_id = "CLIENT_ID" client_secret = "CLIENT_SECRET" udemy = Udemy(client_id, client_secret) print(udemy.courses()) test_filters = [{ "Object": "course", "Setting": "@min", "Additions": ["description"], "Minus": ["title"], }] print(udemy.courses(fields=test_filters))