Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong pkgname error fix #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions aur-comment-fetch
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,32 @@ class Comment(object):


def query(package):
query = AUR.RPC.aur_query('search',package)[0]
query = list(AUR.RPC.aur_query('search',package))
if len(query) == 0:
raise click.ClickException('couldn\'t find any package with name "{0}"'
.format(package))
elif len(query) > 1:
# test if the exact name is under the found then we won't ask
if package in [x['Name'] for x in query]:
return package
number = 0
if len(query) > 1:
for i,x in enumerate(query):
print('\033[33m\033[1m{0}\033[0m: \033[33m{1} \033[32m{2}'
.format(i,x['Name'],x['Version']))
.format(i+1,x['Name'],x['Version']))
print('\t\033[0m{0}'.format(x['Description']))
number = click.prompt('\nspecify the number of the package', type=int)
return query[number]['Name']
else:
return package
number = click.prompt('\nspecify the number of the package', type=click.IntRange(1, len(query))) - 1

return query[number]['Name']

def get(package):
res = requests.get(BASE_URL+package+'/?comments=all',verify=True)
if res.status_code != 200:
res = requests.get(BASE_URL+query(package)+'/?comments=all',verify=True)
package = query(package)
res = requests.get(BASE_URL+package+'/?comments=all',verify=True)
if res.status_code != 200:
raise click.ClickException('couldn\'t fetch comments for package "{0}"'
.format(package))
return res
return package,res

def fetch_comments(package,number=5,get_all=False):
res = get(package)
def fetch_comments(package,number=5):
package,res = get(package)
soup = BeautifulSoup(res.content, 'lxml')
allNews = soup.findAll('div',attrs={'id':'news'})
comments = []
Expand All @@ -55,7 +53,7 @@ def fetch_comments(package,number=5,get_all=False):
timestamps = news.findAll('h4')
contents = news.findAll('div',attrs={'class':'article-content'})
for author,timestamp,content in zip(authors,timestamps,contents):
if not get_all and i >= number:
if str(i) == number:
return package,comments
comments.append(Comment(author.text.strip().split()[0],
" ".join(timestamp.text.strip().split()[3:5]),
Expand All @@ -67,18 +65,18 @@ def fetch_comments(package,number=5,get_all=False):

@click.command()
@click.argument('package')
@click.option('-a','--all','get_all',is_flag=True,help='fetch all comments')
@click.option('-n','--number',type=int,default=5,help='specify number of comments to fetch')
@click.option('-a','--all','number',flag_value='-1',help='fetch all comments')
@click.option('-n','--number',default="5",help='specify number of comments to fetch')
@click.option('-r','--reverse','reverse_order',is_flag=True,help='show comments in reversed order')
def main(package,get_all,number,reverse_order):
package,comments = fetch_comments(package,number=number,get_all=get_all)
def main(package,number,reverse_order):
package,comments = fetch_comments(package,number)
if len(comments) == 0:
print('\033[31m\nno comments available for package "{0}"\n full info at {1}\n\033[0m'
.format(package,BASE_URL+package))
return
else:
print('\033[35m\n{4} {1} comments for package "{0}"{3}:\n full info at {2}\n\033[0m'
.format(package,len(comments),BASE_URL+package,' (most recent last)' if reverse_order else '','All' if get_all else 'Last'))
.format(package,len(comments),BASE_URL+package,' (most recent last)' if reverse_order else '','All' if number == "-1" else 'Last'))
for comment in (reversed(comments) if reverse_order else comments):
if comment.pinned and reverse_order:
print()
Expand Down