Skip to content

Commit

Permalink
Merge pull request #1158 from MakisEu/master
Browse files Browse the repository at this point in the history
[ #1150] Added Random Github Repository Picker plugin
  • Loading branch information
pnhofmann committed Jan 24, 2024
2 parents b2b44d7 + 38aff73 commit 3b120a8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions installer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ python-nmap
yeelight
haversine
FlightRadarAPI
github3.py
66 changes: 66 additions & 0 deletions jarviscli/plugins/random_repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# All plugins should inherite from this library
from github3 import login,GitHub, exceptions
from colorama import Fore
from random import randint
from plugin import alias, plugin, require
# This is the standard form of a plugin for jarvis

# Anytime you make a change REMEMBER TO RESTART Jarvis

# You can run it through jarvis by the name
# in the @plugin tag.


class RandomProjectPicker:
def getRandomRepo(self,repo_gen,jarvis):
repos=[]
try:
for repo in repo_gen:
repos.append(repo)
n=len(repos)
jarvis.say("Number of repo: "+str(n),Fore.YELLOW)
chosen_repo=repos[randint(0,n-1)];
jarvis.say("The Chosen repo is: "+chosen_repo.name,Fore.YELLOW)
except(exceptions.NotFoundError):
jarvis.say("User Not Found!",Fore.RED)
self.run(jarvis)
def loginWithToken(self,jarvis):
auth_token = jarvis.input("Give Jarvis your Github Access Token: ",Fore.YELLOW)
try:
g=login(token=auth_token)
g.me()
repo_gen=g.repositories(type='owner')
self.getRandomRepo(repo_gen,jarvis)
except(exceptions.AuthenticationFailed):
jarvis.say("Inavlid Access Token!",color=Fore.RED)
self.run(jarvis)

def noLogin(self,jarvis):
username = jarvis.input("Give Jarvis your Github username: ",Fore.YELLOW)
g=GitHub()
#try:
repo_gen=g.repositories_by(username)
self.getRandomRepo(repo_gen,jarvis)

def run(self,jarvis):

jarvis.say("Choose login method:",color=Fore.YELLOW)
jarvis.say("1. With Personal Access Token.",color=Fore.YELLOW)
jarvis.say("2. No login.",color=Fore.YELLOW)
jarvis.say("3. Close.",color=Fore.YELLOW)
choice=jarvis.input("Enter your choice: ",color=Fore.GREEN).strip();
while (choice<"1" or choice>"3"):
jarvis.say("Invalid choice!",color=Fore.RED)
choice=jarvis.input("Enter your choice: ",color=Fore.GREEN).strip();
if (choice =="1"):
RandomProjectPicker().loginWithToken(jarvis)
elif (choice == "2"):
RandomProjectPicker().noLogin(jarvis)

@alias('random github repo')
@require(network=True)
@plugin('random repo')

def my_plugin(jarvis, s):
RandomProjectPicker().run(jarvis)

0 comments on commit 3b120a8

Please sign in to comment.