예제 #1
0
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'])
예제 #2
0
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)
예제 #3
0
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
        )
예제 #4
0
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)