-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpyixirc.py
executable file
·114 lines (97 loc) · 3.33 KB
/
pyixirc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/python
"""The script searches ixirc.com and parases
the simple json output"""
import sys
import json
import requests
import argparse
class termcolors:
"""Asign some cheap color output for the shell."""
HEADER = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
RED = '\033[31m'
YELLOW = '\033[33m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def get_args():
"""get all args"""
parser = argparse.ArgumentParser(description='Simple cli search for ixirc',
epilog="Made by ShaggyTwoDope")
parser.add_argument('-V',
'-v',
'--version',
action='version',
version='%(prog)s ' + "0.1")
parser.add_argument('-s',
'--searchterm',
type=str,
help='search string',
required=True,
default=None)
parser.add_argument('-c',
'--chanid',
type=str,
help='channel id, see list:',
required=False)
parser.add_argument('-r',
'--reverse',
action='store_true',
help='reverse order',
required=False)
parser.add_argument('-p',
'--page',
type=str,
help='page number',
required=False,
default=0)
args = parser.parse_args()
searchterm = args.searchterm
chanid = args.chanid
page = args.page
reverse = args.reverse
# conflictdate = args.chanid, args.page
# if all(conflictdate):
# sys.exit('Conflict in options: can not use \
# page option with chanid.')
if chanid == "mg":
chanid = 92
elif chanid == "elite":
chanid = 275
return searchterm, chanid, page, reverse
searchterm, chanid, page, reverse = get_args()
def do_search():
searches = requests.get("http://ixirc.com/api/?q=%s&cid=%s&pn=%s" %
(searchterm, chanid, page)).json()
jsondata = json.loads(str(searches).replace("'", '"'))
jsons = jsondata['results']
return jsons
def print_search():
for item in reversed(do_search()):
title = item['name']
packn = item['n']
botn = item['uname']
chan = item['cname']
netw = item['naddr']
size = item['szf']
print(termcolors.RED + title + termcolors.GREEN + " from", chan,
termcolors.BLUE + "on", netw + termcolors.ENDC)
print(termcolors.RED + size + termcolors.YELLOW + " /msg", botn,
"xdcc send", packn, termcolors.ENDC)
print("---------------------------------------------")
def print_pageinfo():
for item in do_search():
results = item['c']
pagecount = item['pc']
print(termcolors.RED + results + termcolors.GREEN + " results",
termcolors.BLUE + "on total of ", pagecount + termcolors.ENDC)
print("---------------------------------------------")
def main():
try:
print_search()
except KeyError:
print("No Result Found")
if __name__ == '__main__':
main()