commit 55866f1215a2dbedc5ebf3ac97af3e27c4fb93e7
parent da7623dd5e19302d979107e6b4d37242445ee431
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Sun, 11 Oct 2015 02:25:28 +0200
multiple users, no sed
Diffstat:
3 files changed, 44 insertions(+), 46 deletions(-)
diff --git a/README b/README
@@ -6,7 +6,8 @@ Requires Debian packages python3-requests, python3-bs4, python3-lxml
- get_propositions.py USER
returns the list of identifiers of all opinions and modifications of USER
- of the form "/opinions/N" and "/opinions/N/versions/V"
+ of the form "/opinions/N 1" and "/opinions/N/versions/V 1"
+ (the 1 represents a dummy positive vote)
- get_votes.py USER
returns the votes of USER
@@ -25,10 +26,7 @@ Examples:
- to vote for all propositions and opinions of USER
- get_propositions.py USER | sed 's/$/ 1/' | vote.py YOUREMAIL YOURPASS
-
- (Note that users are *not* counted as having voted for their own propositions
- and opinions.)
+ get_propositions.py USER | vote.py YOUREMAIL YOURPASS
WARNING: These scripts are provided to simplify your life only. Please use them
responsibly. The author does not encourage any form of ballot stuffing or other
diff --git a/get_propositions.py b/get_propositions.py
@@ -11,27 +11,27 @@ VERSIONS_URL = 'https://www.republique-numerique.fr/profile/%s/versions'
if __name__ == '__main__':
try:
- user = sys.argv[1]
+ users = sys.argv[1:]
except IndexError:
- print("Usage: %s USER\n"
- "Returns all opinions and modifications of USER" %
+ print("Usage: %s USER...\n"
+ "Returns all opinions and modifications of each USER" %
sys.argv[0], file=sys.stderr)
sys.exit(1)
-
- for url in [PROPOSITIONS_URL % user, VERSIONS_URL % user]:
- data = requests.get(url, headers=HEADERS)
- tree = BeautifulSoup(data.text, 'html.parser')
-
- for div in tree.find_all('div', class_='opinion__data'):
- res_url = None
- for a in div.find_all('a'):
- v = a.get('href')
- if not v:
- continue
- if v.startswith('/consultations'):
- res_url = a.get('href')
- break
-
- print ("%s" % url2res(res_url))
-
+
+ for user in users:
+ for url in [PROPOSITIONS_URL % user, VERSIONS_URL % user]:
+ data = requests.get(url, headers=HEADERS)
+ tree = BeautifulSoup(data.text, 'html.parser')
+
+ for div in tree.find_all('div', class_='opinion__data'):
+ res_url = None
+ for a in div.find_all('a'):
+ v = a.get('href')
+ if not v:
+ continue
+ if v.startswith('/consultations'):
+ res_url = a.get('href')
+ break
+
+ print ("%s 1" % url2res(res_url))
diff --git a/get_votes.py b/get_votes.py
@@ -16,31 +16,31 @@ KEYS = {
if __name__ == '__main__':
try:
- user = sys.argv[1]
+ users = sys.argv[1:]
except IndexError:
- print("Usage: %s USER\n"
- "Returns all votes of USER" %
+ print("Usage: %s USER...\n"
+ "Returns all votes of each USER" %
sys.argv[0], file=sys.stderr)
sys.exit(1)
- data = requests.get(VOTE_URL % user, headers=HEADERS)
- votes_tree = BeautifulSoup(data.text, 'html.parser')
-
- for div in votes_tree.find_all('div', class_='opinion__data'):
- res_url = None
- for a in div.find_all('a'):
- v = a.get('href')
- if not v:
- continue
- if v.startswith('/consultations'):
- res_url = a.get('href')
+ for user in users:
+ data = requests.get(VOTE_URL % user, headers=HEADERS)
+ votes_tree = BeautifulSoup(data.text, 'html.parser')
+
+ for div in votes_tree.find_all('div', class_='opinion__data'):
+ res_url = None
+ for a in div.find_all('a'):
+ v = a.get('href')
+ if not v:
+ continue
+ if v.startswith('/consultations'):
+ res_url = a.get('href')
+ break
+ raw_v = None
+ for span in div.find_all('span'):
+ raw_v = span.get('class')
break
- raw_v = None
- for span in div.find_all('span'):
- raw_v = span.get('class')
- break
- v = KEYS[raw_v[1].split('-')[1]]
-
- print ("%s %s" % (url2res(res_url), v))
+ v = KEYS[raw_v[1].split('-')[1]]
+ print ("%s %s" % (url2res(res_url), v))