Random words to replace the now broken loremipsum module, a few tidyups

pull/13/head
David Trail 10 years ago
parent 0fc430b8de
commit 27f39974b4

1
.gitignore vendored

@ -1,5 +1,6 @@
*.cfg *.cfg
*.pyc *.pyc
.idea/
bin/ bin/
include/ include/
lib/ lib/

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.4.0 (/usr/bin/python3.4)" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Shreddit.iml" filepath="$PROJECT_DIR$/.idea/Shreddit.iml" />
</modules>
</component>
</project>

@ -0,0 +1,5 @@
<component name="DependencyValidationManager">
<state>
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</state>
</component>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -1,20 +1,34 @@
#!/usr/bin/env python3 #!/usr/bin/env python
import praw import os
from praw.errors import *
import argparse import argparse
from re import sub
from random import shuffle, randint
from simpleconfigparser import simpleconfigparser from simpleconfigparser import simpleconfigparser
from praw.objects import Comment, Submission
from datetime import datetime, timedelta from datetime import datetime, timedelta
from re import sub
from time import sleep import praw
from praw.errors import InvalidUser, InvalidUserPass, RateLimitExceeded
from praw.objects import Comment, Submission
try: try:
from loremipsum import get_sentence from loremipsum import get_sentence # This only works on Python 2
except ImportError: except ImportError:
def get_sentence(): if os.name == 'posix':
return '''I have been Shreddited for privacy!\n\n\ try:
https://github.com/x89/Shreddit/''' # Try to generate a random string of words
fh = open('/usr/share/dict/words')
words = fh.read().splitlines()
fh.close()
shuffle(words)
def get_sentence():
return ' '.join(words[:randint(50, 150)])
except FileNotFoundError:
def get_sentence():
return '''I have been Shreddited for privacy!\n\n\
https://github.com/x89/Shreddit/'''
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
@ -52,12 +66,12 @@ def login(user=None, password=None):
r.login(_user, _pass) r.login(_user, _pass)
else: else:
r.login() # Let the user supply details r.login() # Let the user supply details
except InvalidUser as e:
raise InvalidUser("User does not exist.", e)
except InvalidUserPass as e: except InvalidUserPass as e:
raise InvalidUserPass(e) raise InvalidUserPass("Specified an incorrect password.", e)
except RateLimitExceeded: except RateLimitExceeded as e:
raise RateLimitExceeded() raise RateLimitExceeded("You're doing that too much.", e)
except NonExistentUser:
raise NonExistentUser("User does not exist")
login(user=_user, password=_pass) login(user=_user, password=_pass)

Loading…
Cancel
Save