From e0913ec2a8207b4f719517e33d0bfa10688ab840 Mon Sep 17 00:00:00 2001 From: Juanjo Conti Date: Mon, 23 Nov 2015 12:16:24 -0300 Subject: [PATCH 01/13] Add config.py --- config.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 config.py diff --git a/config.py b/config.py new file mode 100644 index 0000000..74754ad --- /dev/null +++ b/config.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +FIND_THE_WORDS = "Find the words: " +BOTTOM_TEXT = "Generated with ❤" From f459de79f4f084c534ee19e19ceaebdca7ad4536 Mon Sep 17 00:00:00 2001 From: Juanjo Conti Date: Mon, 23 Nov 2015 12:20:31 -0300 Subject: [PATCH 02/13] Fixes to generate a better pdf version --- wordsearch.py | 85 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/wordsearch.py b/wordsearch.py index 77ad3cc..a9bc2a3 100644 --- a/wordsearch.py +++ b/wordsearch.py @@ -1,7 +1,10 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- import random +from config import * + # Directions are: # +. left to right # -. right to left @@ -32,7 +35,7 @@ def read_words(filename): styles = { 'easy': ('10x10', ('+.', '.+')), 'standard': ('15x15', ('+-', '+.', '++', '.+', '.-', '-.')), - 'hard': ('20x20', all_directions), + 'hard': ('15x15', all_directions) } dirconv = { @@ -46,47 +49,62 @@ def read_words(filename): class Grid(object): def __init__(self, wid, hgt): self.wid = wid - self.hgt = hgt - self.data = ['.'] * (wid * hgt) - self.used = [' '] * (wid * hgt) + self.hgt = hgt + self.data = ['.'] * (wid * hgt) + self.used = [' '] * (wid * hgt) self.words = [] def to_text(self): result = [] - for row in xrange(self.hgt): - result.append(''.join(self.data[row * self.wid : + for row in xrange(self.hgt): + result.append(''.join(self.data[row * self.wid : (row + 1) * self.wid])) - return '\n'.join(result) - + return '\n'.join(result) + def used_to_text(self): result = [] - for row in xrange(self.hgt): - result.append(''.join(self.used[row * self.wid : + for row in xrange(self.hgt): + result.append(''.join(self.used[row * self.wid : (row + 1) * self.wid])) - return '\n'.join(result) + return '\n'.join(result) - def to_pdf(self, filename): + def to_pdf(self, filename, words): from reportlab.pdfgen import canvas - from reportlab.lib.pagesizes import letter, A4 - - pagesize = A4 - paper = canvas.Canvas(filename, pagesize=pagesize) - margin = 50 - printwid, printhgt = map(lambda x: x - margin * 2, pagesize) + from reportlab.lib.pagesizes import cm, A4 + from reportlab.platypus import SimpleDocTemplate, Table, TableStyle + from reportlab.lib import colors + from reportlab.platypus.paragraph import Paragraph + from reportlab.lib.styles import ParagraphStyle + from reportlab.platypus.flowables import Spacer - gx = margin - gy = printhgt - margin - gdx = printwid / self.wid - gdy = printhgt / self.hgt - for y in xrange(self.hgt): - cy = gy - y * gdy - for x in xrange(self.wid): - cx = gx + x * gdx - p = x + self.wid * y - c = self.data[p] - paper.drawString(cx, cy, c) - paper.showPage() - paper.save() + doc = SimpleDocTemplate(filename, pagesize=A4) + data = [self.data[x: x + self.wid] for x in range(0, len(self.data), self.wid)] + l = cm * 1.25 + t=Table(data, len(data[0]) * [l], len(data) * [l]) + t.setStyle(TableStyle([('ALIGN',(0,0),(-1,-1),'CENTER'), + ('VALIGN',(0,0),(-1,-1),'TOP'), + ('BOX', (0,0), (-1,-1), 1, colors.black), + ('FONTSIZE', (0,0), (-1,-1), 20) + ])) + style = ParagraphStyle( + 'default', + fontName='Times-Roman', + fontSize=18, + leading=18, + spaceBefore=10, + spaceAfter=10, + bulletFontName='Times-Roman', + bulletFontSize=18, + bulletIndent=0, + ) + elements = [Paragraph(FIND_THE_WORDS, style, None)] + elements.append(Paragraph(", ".join(words), style)) + elements.append(Spacer(1, 0.5 * cm)) + elements.append(t) + style.fontSize = 12 + elements.append(Spacer(1, 0.5 * cm)) + elements.append(Paragraph(BOTTOM_TEXT, style, None)) + doc.build(elements) def pick_word_pos(self, wordlen, directions): xd, yd = random.choice(directions) @@ -177,11 +195,12 @@ def make_grid(stylep="standard", words=[], tries=100): if __name__ == '__main__': import sys random.seed() - grid = make_grid(sys.argv[1], sys.argv[2:]) + words = sys.argv[2:] + grid = make_grid(sys.argv[1], words) if grid is None: print "Can't make a grid" else: print grid.to_text() print print grid.used_to_text() - grid.to_pdf("ws.pdf") + grid.to_pdf(words[0] + ".pdf", words) From b3936b381541f735f19ddf28bd7ad0b70b08a4ce Mon Sep 17 00:00:00 2001 From: Juanjo Conti Date: Mon, 23 Nov 2015 12:21:08 -0300 Subject: [PATCH 03/13] Add example --- output_example.pdf | Bin 0 -> 4108 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 output_example.pdf diff --git a/output_example.pdf b/output_example.pdf new file mode 100644 index 0000000000000000000000000000000000000000..335616356d21cf857633b16acb192d6ed42b6ba7 GIT binary patch literal 4108 zcma)9*S4Zsm%gtt>K!l#Hj)HPprWFfFo0r~B#Hzj{B=%W^b2&~^?g5UgX4d5(v{e53CG$W3{a^nJER2Wehhs$r`i5)xN@(antODqs7CD9+ z0@pBn)L{7Aw{Io?UDsCBlIA&Izn}mDc&hdFOQQk69139Zei5%Q0RO(if%5x`VZMGb zT>V}7rS;Q_RRV+a;wbRIu>WO*H%$THo~wEK%{2jdeRJDxaQnAlsyN1bEO;5I;h&Fq zBgS|1;}O4k`T88~mC4^k6K{?YKnu@N+vmiE9u87XZ~*8sjlB^qazZe*n99j{roKC}9*q0+ljas#K~K-~hlg#eZR4 z`LI|RffxCj5diPVzH0iyI`%d5J#A@(u`Br1B(P}w5o5F>fzBJYONYM*M-sHRkNNM&CEFv$5ft;T6EjSoyu| zK^T`Z{!jFkKs{D%FUx1^qYdXuBVKSCES{OQM5XiWDX zk7Ht)-){Xmoaiuwd(i}1VNY7r$e3Nlc35IQ;@3H_(Cuf8JS|__Va9Zh`4qRElMXKmO;2NC`HcQ@d>Aec3sbG=I4IuSK z7HYd}F?Br{s#yWI2lZm2y$dZ-*}ScHQWg9-<8!TaCu&Un0S$*$jo)#8LbA>ss+vZ8 z|I{xVjMI{uZxy(5 zU8J4aS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>o;Jp8I^OW`^(an@Gh+!wd$L;DEY*V-k(^i| zk;A&-XK1>LmUP7Fr&~mgzmUc;F4Mj#UiTTv<45t2JVkDJs5%b#9%?yc!lN3!G*-HE zO>tEVd?H1!AN*A@u1e6%P4O9f?hm^dsFUeH7M}PTKk_9vGM)+Es8{e40~*a?5agWbni_?pb$N9LcC_UB3P58t?a{el1}8sC3j07(!y z0leOPzo>Yod|iP1Q-)&k82O6~!+)3IM9eOJ(JPa`>ycDU41Uq0$e3~cRffjf-(_UX zJO8SO6O~W0&{uA@;eU`>zWd@QnNQ@{{Cjc?L4baXxko&x|9?EW5PRC?r9FaBdjv(k z*?XMA_js9zCB$U7$8hYr#|SLk<2ZUQ0RLR|5PODs_u>IBViPl?h3AF9i#)~a Date: Mon, 23 Nov 2015 12:27:11 -0300 Subject: [PATCH 04/13] Update to english --- output_example.pdf | Bin 4108 -> 4020 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/output_example.pdf b/output_example.pdf index 335616356d21cf857633b16acb192d6ed42b6ba7..36135dda297c2940829eaa390e48a52ef59dc4f1 100644 GIT binary patch delta 2499 zcma)6Nw%tp0X>z<=%4)55>j?3cJ!@)bRss0sGtaMCKRDi>$-?(sqlg4;xbmbUu2Gf&vNGWVC7ey*Q|&vTxtZ+1R%UFU1V8~=Mg2--MuT#+1Zf}bLKsKqMfcX?&(=YM334?dDOi} zR(G2XVGwjcF_QY?3U8I@@p4}%oi5^@+kMzqG4Gxaj{#LyQRzJ`qt`!LF1!D(ZBTy#ikT|igtml`yxR`gYdo5aJrwt}Kfo)9iv zr_FuySsOR2s&VtVa~fVA{!t)S!J{_Uoq;WU(Uf^!Tz%SarK7Tp1rh1gjVz-F;_;FYw^-p=M9&asRAo+ zMQxWptyXthL|#|<@^viR#0jg5)|e~z=_yr3xYA+nSxHdgucl%Wo6My&!;?B{sI;9- zu3PMaQhMNeFtsq*K0XR#IhnR#X((Sm3O!tk-%A-}p^6rO$F8Cdn|nH*^(+*!-h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~RhF&KNUgn0ltKLSMPnr5c*kRqCDqkOdBMp4kQz$$34Qrf^}cgkF_}16qiA$bnR)wuUQlbS z#kaog5>-K13XQ8*qvx~b6a2bX{qQ)$PYdg$EA!`DZTsr?zBaZhCMs0fs0cUNGPK zK9s>Ip;1=v;{3bROPDS~{l!z{+fjlQ?l{Qon&k>fEUV#VW8dqf;8A&zG27F Date: Tue, 1 Dec 2015 12:46:11 -0300 Subject: [PATCH 05/13] Allow words with spaces. Example: python wordsearch.py hard word "two words" "more words here" final --- wordsearch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wordsearch.py b/wordsearch.py index a9bc2a3..a92c0e2 100644 --- a/wordsearch.py +++ b/wordsearch.py @@ -196,7 +196,7 @@ def make_grid(stylep="standard", words=[], tries=100): import sys random.seed() words = sys.argv[2:] - grid = make_grid(sys.argv[1], words) + grid = make_grid(sys.argv[1], ["".join(w.lower().split()) for w in words]) if grid is None: print "Can't make a grid" else: From c0b0ef90d9ed62ee3e0b542c45e5f4855b180bfb Mon Sep 17 00:00:00 2001 From: Juanjo Conti Date: Tue, 15 Dec 2015 16:53:31 -0300 Subject: [PATCH 06/13] Fix to allow not onlt ascii input --- wordsearch.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wordsearch.py b/wordsearch.py index a92c0e2..89f4938 100644 --- a/wordsearch.py +++ b/wordsearch.py @@ -44,7 +44,7 @@ def read_words(filename): '+': 1, } -letters = "abcdefghijklmnopqrstuvwxyz" +letters = u"abcdefghijklmnñopqrstuvwxyz" class Grid(object): def __init__(self, wid, hgt): @@ -196,11 +196,12 @@ def make_grid(stylep="standard", words=[], tries=100): import sys random.seed() words = sys.argv[2:] - grid = make_grid(sys.argv[1], ["".join(w.lower().split()) for w in words]) + words_to_use = [unicode("".join(w.lower().split()), 'utf-8') for w in words] + grid = make_grid(sys.argv[1], words_to_use) if grid is None: print "Can't make a grid" else: print grid.to_text() print print grid.used_to_text() - grid.to_pdf(words[0] + ".pdf", words) + grid.to_pdf(words_to_use[0] + ".pdf", words) From cf8ecf05540019d0e352c05420b12d0a928daed2 Mon Sep 17 00:00:00 2001 From: Juanjo Conti Date: Tue, 15 Dec 2015 16:54:14 -0300 Subject: [PATCH 07/13] Ignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..80990f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.pyc +*.pdf +stocks/* +.idea/* From bc5762096cb03fe5b280a189d38c69f2ecefaac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Conti?= Date: Tue, 15 Dec 2015 20:57:53 -0300 Subject: [PATCH 08/13] Update and rename README to README.md --- README | 21 --------------------- README.md | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 21 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index a62cd1c..0000000 --- a/README +++ /dev/null @@ -1,21 +0,0 @@ -Wordsearch generator -==================== - -Currently, this is a simple command-line script which generates a wordsearch -grid. - -Usage: - - python wordsearch.py [word...] - -The grid size, and permissible directions for words, is controlled by the -difficulty setting, which is one of easy, normal and hard. - -The output grid is displayed on stdout, and written to a pdf file. - -Much work still remains to make the output nice. - -Requirements -============ - -reportlab Python library (https://pypi.python.org/pypi/reportlab) diff --git a/README.md b/README.md new file mode 100644 index 0000000..836f4df --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +Wordsearch generator +==================== + +(o Generador de sopas de letras) + +Based on https://github.com/rboulton/wordsearch + +Currently, this is a simple command-line script which generates a wordsearch +grid. + +Usage: + + python wordsearch.py [word...] + +The grid size, and permissible directions for words, is controlled by the +difficulty setting, which is one of `easy`, `normal` and `hard`. + +The output grid is displayed on stdout, and written to a pdf file called with the same name of the first word. + + +Requirements +============ + +reportlab Python library (https://pypi.python.org/pypi/reportlab) + +Improvements from the original version +====================================== + +* Configurable header and footer +* Allow words with spaces (using quotes). Example: `python wordsearch.py hard word1 "word with spaces" word3 +* Allow not only ascii input (for example, words with ñ or á é í ó ú are fine) From bf2fd3efe7dd3a2c66eebbfa0af8a215fba1e765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Conti?= Date: Tue, 15 Dec 2015 20:59:10 -0300 Subject: [PATCH 09/13] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 836f4df..3e95deb 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,11 @@ grid. Usage: - python wordsearch.py [word...] + python wordsearch.py [word...] + +Example: + + python wordsearch.py easy duck "polar bear" dog horse rabbit The grid size, and permissible directions for words, is controlled by the difficulty setting, which is one of `easy`, `normal` and `hard`. From f58ba61a3aad373fd8fa69ed2b2571d2aa70c031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Conti?= Date: Tue, 15 Dec 2015 21:00:58 -0300 Subject: [PATCH 10/13] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3e95deb..8e0f578 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ difficulty setting, which is one of `easy`, `normal` and `hard`. The output grid is displayed on stdout, and written to a pdf file called with the same name of the first word. +Example of the generated pdf: https://github.com/jjconti/sopa-de-letras/blob/master/output_example.pdf Requirements ============ @@ -30,6 +31,7 @@ reportlab Python library (https://pypi.python.org/pypi/reportlab) Improvements from the original version ====================================== +* Better pdf layout * Configurable header and footer * Allow words with spaces (using quotes). Example: `python wordsearch.py hard word1 "word with spaces" word3 * Allow not only ascii input (for example, words with ñ or á é í ó ú are fine) From abcc7e8d9a29bb280eb9a7fdc735ed3765e6495d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Conti?= Date: Tue, 15 Dec 2015 21:06:19 -0300 Subject: [PATCH 11/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e0f578..aeaf9cf 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Example of the generated pdf: https://github.com/jjconti/sopa-de-letras/blob/mas Requirements ============ -reportlab Python library (https://pypi.python.org/pypi/reportlab) +* Reportlab (https://pypi.python.org/pypi/reportlab) Improvements from the original version ====================================== From e908e8029f62c7f253f7a7d0ab1be628d860af67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Conti?= Date: Tue, 15 Dec 2015 21:24:27 -0300 Subject: [PATCH 12/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aeaf9cf..5a4a75e 100644 --- a/README.md +++ b/README.md @@ -33,5 +33,5 @@ Improvements from the original version * Better pdf layout * Configurable header and footer -* Allow words with spaces (using quotes). Example: `python wordsearch.py hard word1 "word with spaces" word3 +* Allow words with spaces (using quotes). Example: `python wordsearch.py hard word1 "word with spaces" word3` * Allow not only ascii input (for example, words with ñ or á é í ó ú are fine) From caa1704ba113a0eafdf3dc92150cb38abf297712 Mon Sep 17 00:00:00 2001 From: Juanjo Conti Date: Wed, 6 Jan 2016 12:58:35 -0300 Subject: [PATCH 13/13] Remove unused code --- wordsearch.py | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/wordsearch.py b/wordsearch.py index 89f4938..98270d2 100644 --- a/wordsearch.py +++ b/wordsearch.py @@ -11,25 +11,6 @@ # .+ top to bottom # .- bottom to top -def read_words(filename): - words = set() - fd = open(filename) - try: - for line in fd.readlines(): - if "'" in line: - continue - line = line.strip().lower() - if len(line) > 3 and len(line) < 7: - words.add(line) - finally: - fd.close() - return words - -all_words = read_words('/usr/share/dict/words') -explicit_words = ('fuck', 'cunt', 'piss', 'bloody', 'shit', 'boob') -for word in explicit_words: - all_words.add(word) - all_directions = ('+-', '+.', '++', '.+', '.-', '--', '-.', '-+') styles = { @@ -158,9 +139,6 @@ def fill_in_letters(self): if self.data[p] == '.': self.data[p] = random.choice(letters) - def remove_bad_words(self): - return True - def make_grid(stylep="standard", words=[], tries=100): # Parse and validate the style parameter. size, directions = styles.get(stylep, (stylep, all_directions)) @@ -176,22 +154,16 @@ def make_grid(stylep="standard", words=[], tries=100): for direction in directions] while True: - while True: - grid = Grid(wid, hgt) - if grid.place_words(words, directions): - break - tries -= 1 - if tries <= 0: - return None - - grid.fill_in_letters() - if grid.remove_bad_words(): - return grid - + grid = Grid(wid, hgt) + if grid.place_words(words, directions): + break tries -= 1 if tries <= 0: return None + grid.fill_in_letters() + return grid + if __name__ == '__main__': import sys random.seed()