Simplify voting code

Not sure if I keep this feature, but at least I can now see if anybody
is still using it...
This commit is contained in:
Tobias Gruetzmacher 2019-11-03 20:44:07 +01:00
parent ac9d8db1e8
commit e24c0ae557
5 changed files with 8 additions and 19 deletions

View file

@ -203,17 +203,8 @@ def vote_comic(scraperobj):
out.context = scraperobj.name
try:
name = scraperobj.name
answer = scraperobj.vote()
out.debug(u'Vote answer %r' % answer)
if answer == 'counted':
url = configuration.Url + 'comics/%s.html' % name.replace('/', '_')
out.info(u'Vote submitted. Votes are updated regularly at %s.' % url)
elif answer == 'no':
out.info(u'Vote not submitted - your vote has already been submitted before.')
elif answer == 'noname':
out.warn(u'The comic %s cannot be voted.' % name)
else:
out.warn(u'Error submitting vote parameters: %r' % answer)
scraperobj.vote()
out.info(u'Vote submitted.')
except Exception as msg:
out.exception(msg)
errors += 1

View file

@ -13,7 +13,7 @@ App = AppName + u' ' + __version__
Maintainer = u'Tobias Gruetzmacher'
MaintainerEmail = u'tobias-dosage@23.gs'
Url = u'http://dosage.rocks/'
Url = u'https://dosage.rocks/'
SupportUrl = u'https://github.com/webcomics/dosage/issues'
UserAgent = u"Mozilla/5.0 (compatible; %s/%s; +%s)" % (AppName, __version__,
Url)
@ -25,4 +25,4 @@ Freeware = AppName + u""" comes with ABSOLUTELY NO WARRANTY!
This is free software, and you are welcome to redistribute it
under certain conditions. Look at the file `COPYING' within this
distribution."""
VoteUrl = "http://gaecounter.appspot.com/"
VoteUrl = "https://buildbox.23.gs/count/"

View file

@ -259,11 +259,10 @@ class Scraper(object):
def vote(self):
"""Cast a public vote for this comic."""
url = configuration.VoteUrl + 'count/'
uid = get_system_uid()
data = {"name": self.name.replace('/', '_'), "uid": uid}
page = urlopen(url, self.session, data=data)
return page.text
response = self.session.post(configuration.VoteUrl, data=data)
response.raise_for_status()
def get_download_dir(self, basepath):
"""Try to find the corect download directory, ignoring case

View file

@ -54,4 +54,4 @@ def zenpencils():
add(GET, re.compile(r'https://cdn-zenpencils\.netdna-ssl\.com/wp-content/uploads/.*\.jpg'), _img(), content_type='image/jpeg')
def vote():
add(POST, 'http://gaecounter.appspot.com/count/', 'no')
add(POST, 'https://buildbox.23.gs/count/', '')

View file

@ -20,5 +20,4 @@ class TestVote(object):
@responses.activate
def test_vote(self):
httpmocks.vote()
answer = ATestScraper('Test_Test').vote()
assert answer in ('counted', 'no'), 'invalid answer %r' % answer
ATestScraper('Test_Test').vote()