Improved example_import and added information to docs
authorSteven Tobin <steventtobin (at) gmail.com>
Tue, 9 Sep 2014 02:19:25 +0000 (12:19 +1000)
committerSteven Tobin <steventtobin (at) gmail.com>
Tue, 9 Sep 2014 02:19:25 +0000 (12:19 +1000)
README.rst
setup.py
xkcdpass/example_import.py

index 970f99df7e347033aa02b10707ac883b4578a97b..7fe4ffc38ea8d73eba2e58d6642760c380203f63 100644 (file)
@@ -97,10 +97,28 @@ A concise overview of the available ``xkcdpass`` options can be accessed via::
 
 A large wordlist is provided (courtesy of `12Dicts <http://wordlist.aspell.net/12dicts/>`_) for convenience, but the generator can be used with any word file of the correct format: a file containing one 'word' per line. The default word file can be found in ``xkcdpass/static/default.txt``.
 
-The main script can also be imported into other python code, and an example of this usage is provided in the package (``xkcdpass/example_import.py``).
+
+
+Advanced Usage
+==============
+
+The built-in functionality of ``xkcdpass`` can be extended by importing the module into custom python scripts.
+An example of this usage is provided in `example_import.py <https://github.com/redacted/XKCD-password-generator/blob/master/xkcdpass/example_import.py>`_, which randomly capitalises the letters in a generated password. 
+
+A simple use of import:: 
+
+    import xkcdpass.xkcd_password as xp
+
+    ## create a wordlist from the default wordfile
+    ## use words between 5 and 8 letters long
+    wordfile = xp.locate_wordfile()
+    mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) 
+
+    ## create a password with the acrostic "face"
+    print(xp.generate_xkcdpassword(mywords, acrostic="face")) 
 
 
 
 License
 =======
-The BSD License (BSD)
\ No newline at end of file
+The BSD License (BSD)
index 3847e403eae6592bb23bd31def5ce2795aca2375..f5346708092b1aa6efb8414561ef0123b8a13f29 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@ from setuptools import setup
 
 setup(
     name='xkcdpass',
-    version='1.2.0',
+    version='1.2.1',
     author='Steven Tobin',
     author_email='steventtobin@gmail.com',
     url='https://github.com/redacted/XKCD-password-generator',
index 2dd7a25ec4897c4dbf044b0377fc236d73be0098..48cd3ce732919ec9cce65b3404e3e0e45d90a246 100644 (file)
@@ -1,8 +1,22 @@
-# import the generate_xkcdpassword and generate_wordlist functions
-from xkcd_password import generate_wordlist, generate_xkcdpassword
+import xkcdpass.xkcd_password as xp
+import random
 
-# create a wordlist
-mywords = generate_wordlist(wordfile='3esl.txt', min_length=5, max_length=8,)
+## create a wordlist
+#mywords = generate_wordlist(wordfile='3esl.txt', min_length=5, max_length=8,)
 
-# create a password with the acrostic 'face'
-print(generate_xkcdpassword(mywords, acrostic="face"))
+## create a password with the acrostic 'face'
+#print(generate_xkcdpassword(mywords, acrostic="face"))
+
+def random_capitalisation(s, chance):
+    new_str = []
+    for i, c in enumerate(s):
+        new_str.append(c.upper() if random.random() < chance else c)
+    return "".join(new_str)
+
+
+words = xp.locate_wordfile()
+mywords = xp.generate_wordlist(wordfile=words, min_length=5, max_length=8)
+raw_password = xp.generate_xkcdpassword(mywords)
+for i in range(5):
+    print random_capitalisation(raw_password, i/10.0)  
git clone https://git.99rst.org/PROJECT