কম্পিউটার টিউটোরিয়াল

পাইথনে GitHub-এ কোনো ইউজারের টপ ১০ স্টার্ড রিপোজিটরি বের করুন

Git হলো সবচেয়ে জনপ্রিয় ভার্সন কন্ট্রোল সিস্টেম, যেখানে মিলিয়ন মিলিয়ন ডেভেলপার তাদের প্রজেক্ট বা ফাইল (কোড) পরিচালনা করেন। এখানে আমরা একজন ইউজারের মাসিক টপ ১০ সবচেয়ে বেশি স্টার করা রিপোজিটরি বের করার চেষ্টা করব।

যেহেতু আমরা মূলত GitHub রিপোজিটরি স্ক্রেপ করব, তাই প্রধানত Requests এবং BeautifulSoup লাইব্রেরি ব্যবহার করব।

ফলাফল একটি ফাইলে সংরক্ষণ করব এবং প্রদর্শন করব। এটি পজিশন (স্টার অনুযায়ী), নাম ও রিপোজিটরি দেখাবে।

বাস্তবায়ন কোড

import requests
from bs4 import BeautifulSoup

r = requests.get('https://github.com/trending/lua?since=monthly')
bs = BeautifulSoup(r.text, 'lxml')
lista_repo = bs.find_all('ol', class_='repo-list')

f1 = open('starred-repos.txt', 'w')
for lr in lista_repo:
    aux = lr.find_all('div', class_='d-inline-block col-9 mb-1')
    for ld in aux:
        rank = ld.find_all('a')
        f1.writelines(str(rank))
        f1.writelines('\n')
f1.close()

f1 = open('starred-repos.txt', 'r')
texto = []
for x in f1:
    if x[0] == '[' and x[1] == '<' and x[2] == 'a':
        na = x.split('"')
        texto.append(na[1])
f1.close()

f1 = open('starred-repos.txt', 'w')
f1.writelines('{}\t {}\t\t {}\t\n\n'.format('Position ', 'Name ', 'Repositories '))
for i in range(10):
    tex = texto[i].split('/')
    name = tex[1]
    repos = tex[2]
    f1.writelines('{}- \t {}\t\t {}'.format(i + 1, name, repos))
    f1.writelines('\n')
f1.close()

f1 = open('starred-repos.txt', 'r')
print(f1.read())
f1.close()

আউটপুট

Position          Name            Repositories
1-                skywind3000     z.lua
2-                Kong            kong
3-                Gawen           WireHub
4-                PapyElGringo    material-awesome
5-                koreader        koreader
6-                stijnwop        guidanceSteering
7-                Courseplay      courseplay
8-                Tencent         LuaPanda
9-                ntop            ntopng
10-               awesomeWM       awesome
  1. পাইথন ব্যবহার করে স্টপওয়াচ তৈরি করা

  2. পাইথনে WhatsApp অটোমেশন (WhatsApp using Python)

  3. পাইথনে News API ব্যবহার করে শীর্ষ সংবাদ আনা

  4. পাইথনে cx_Freeze ব্যবহার করে এক্সিকিউটেবল বানানো