Skip to content

Commit 73e4e46

Browse files
committed
Fixed readme & style, removed special cases from random pool.
1 parent f4cd21e commit 73e4e46

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Such a thing exists.
2020
[![Build Status](https://travis-ci.org/chubin/cheat.sh.svg?branch=master)](https://travis-ci.org/chubin/cheat.sh)
2121

2222
## Features
23-
notnot
23+
2424
**cheat.sh**
2525

2626
* Has a simple curl/browser interface.

lib/routing.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,42 @@ def _get_page_dict(self, query, topic_type, request_options=None):
109109
return self._adapter[topic_type]\
110110
.get_page_dict(query, request_options=request_options)
111111

112-
113-
def handle_if_random_request(self,topic):
112+
def handle_if_random_request(self, topic):
114113
"""
115114
Check if the `query` if a :random one, if yes we check its correctness and then randomly select a topic, based on the provided prefix.
116115
117116
"""
118-
def __select_random_topic(prefix,topic_list):
117+
118+
def __select_random_topic(prefix, topic_list):
119119
#Here we remove the special cases
120-
if ":list" in topic_list: topic_list.remove(":list")
121-
if "rosetta/" in topic_list: topic_list.remove("rosetta/")
122-
#Here we still check that topic_list in not empty
123-
if not topic_list:
120+
if "rosetta/" in topic_list:
121+
topic_list.remove("rosetta/")
122+
123+
cleaned_topic_list = [ x for x in topic_list if ':' not in x]
124+
125+
#Here we still check that cleaned_topic_list in not empty
126+
if not cleaned_topic_list:
124127
return prefix
125-
random_topic = random.choice(topic_list)
128+
129+
random_topic = random.choice(cleaned_topic_list)
126130
return prefix + random_topic
127131

128132
if topic.endswith('/:random') or topic.lstrip('/') == ':random':
129133
#We strip the :random part and see if the query is valid by running a get_topics_list()
130-
if topic.lstrip('/') == ':random' : topic = topic.lstrip('/')
134+
if topic.lstrip('/') == ':random' :
135+
topic = topic.lstrip('/')
131136
prefix = topic[:-7]
137+
132138
topic_list = [x[len(prefix):]
133139
for x in self.get_topics_list()
134140
if x.startswith(prefix)]
135-
if '' in topic_list: topic_list.remove('')
141+
142+
if '' in topic_list:
143+
topic_list.remove('')
144+
136145
if topic_list:
137146
# This is a correct formatted random query like /cpp/:random as the topic_list is not empty.
138-
random_topic = __select_random_topic(prefix,topic_list)
147+
random_topic = __select_random_topic(prefix, topic_list)
139148
return random_topic
140149
else:
141150
# This is a wrongly formatted random query like /xyxyxy/:random as the topic_list is empty
@@ -145,8 +154,6 @@ def __select_random_topic(prefix,topic_list):
145154

146155
#Here if not a random requst, we just forward the topic
147156
return topic
148-
149-
150157

151158
def get_answer_dict(self, topic, request_options=None):
152159
"""

0 commit comments

Comments
 (0)