Tracery Self Generated HTML

In [6]:
import tracery
In [5]:
rules={
    "email":"#name#@#domain#.#domainType#",
    "name":["galaxy","world","solar","tiri", "seb"],
    "domain":["gmail","yahoo","nyu","chess"],
    "domainType":["com","edu","io","cc","net"]
}
grammar=tracery.Grammar(rules)
grammar.flatten("#email#")
Out[5]:
In [16]:
import json
In [33]:
first_names= json.loads((open("text_examples/CorporaFirstNames.json").read()))
In [34]:
last_names= json.loads((open("text_examples/CorporaLastNames.json").read()))
In [8]:
from tracery.modifiers import base_english
In [32]:
rules={
    "email":"#first.lowercase#.#last.lowercase#@#domain#.#domainType#",
    "first":first_names,
    "last":lastNames,
    "domain":["gmail","yahoo","nyu","chess","whaterver"],
    "domainType":["com","edu","io","cc","net","xyz","xxx","org"]
}
grammar=tracery.Grammar(rules)
grammar.add_modifiers(base_english)
grammar.flatten("#email#")
Out[32]:
In [35]:
tech= json.loads((open("text_examples/CorporaTechNames.json").read()))
In [86]:
rules={
    "email":"#first.lowercase#.#last.lowercase#@#domain.lowercase#.#domainType#",
    "first":firstNames,
    "last":lastNames,
    "domain":tech,
    "domainType":["com","edu","io","cc","net","xyz","xxx","org","gov","ai","com","com","me"]
}
grammar=tracery.Grammar(rules)
grammar.add_modifiers(base_english)
for i in range(10):
    print(grammar.flatten("#email#"))

Routes

In [36]:
rules={
    "url":["symbiosis.live/#routes#","symbiosis.live/#routes#","symbiosis.live/#routes#.#type#"],
    "routes":["#route#","#route#-#route#","#route#/#route#/#route#"],
    "route":["#techNames#", "#techNames#","#techNames#","#routes#",],
    "techNames":tech,
    "type":["pdf","php","html","img","png","html","php"]
}
grammar=tracery.Grammar(rules)
for i in range(10):
    print(grammar.flatten("#url#"))
symbiosis.live/NLTK
symbiosis.live/Java/MarkDown/Perl
symbiosis.live/Cassandra-Rspec.png
symbiosis.live/MarkDown-Javascript/SpoonRocket-Heroku/Amazon.php
symbiosis.live/GoogleMaps-Netflix-Cassandra
symbiosis.live/Bower/Silverlight/Canvas
symbiosis.live/HTML5
symbiosis.live/UbuWeb-PushNotifications
symbiosis.live/Twilio/MarkDown/Lisp
symbiosis.live/AppleScript/Yelp/Flash

Phone numbers

In [52]:
rules={
    "phone":["#n##n##n#.#n##n##n#.#n##n##n##n#","#n##n##n# #n##n##n# #n##n##n##n#","#n##n##n#-#n##n##n#-#n##n##n##n#","(#n##n##n#)-#n##n##n#-#n##n##n##n#"],
    "n":["1","2","3","4","5","6","7","8","9"]
}
grammar=tracery.Grammar(rules)
for i in range(10):
    print(grammar.flatten("#phone#"))
(671)-237-4259
288-242-8821
567 561 9617
215-876-8784
(351)-351-5637
138 174 2588
584-342-4446
784 121 9326
134-236-9486
498.945.7336
In [60]:
htmlHead="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />"
In [61]:
print (htmlHead)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
In [92]:
mainTextWiki="""Holden, formally known as General Motors Holden, is an Australian automobile importer and a former automobile manufacturer with its headquarters in Port Melbourne, Victoria. The company was founded in 1856 as a saddlery manufacturer in South Australia. In 1908 it moved into the automotive field, becoming a subsidiary of the United States-based General Motors (GM) in 1931, when the company was renamed General Motors-Holden's Ltd. It was renamed Holden Ltd in 1998, and General Motors Holden in 2005.

Holden sells the remaining stock of the locally produced range of Commodore vehicles, and imported GM models. Holden has offered badge engineered models in sharing arrangements with Chevrolet, Isuzu, Nissan, Opel, Suzuki, Toyota and Vauxhall Motors. In 2013 the vehicle lineup consisted of models from GM Korea, GM Thailand, GM in the US, and self-developed Commodore, Caprice, and Ute. Holden also distributed the European Opel brand in Australia in 2012 until the Opel brand's Australian demise in mid-2013.[1]

From 1994 to 2017, all Australian-built Holden vehicles were manufactured in Elizabeth, South Australia, and engines were produced at the Fishermans Bend plant in Melbourne. Historically, production or assembly plants were operated in all mainland states of Australia. The consolidation of car production at Elizabeth was completed in 1988, but some assembly operations continued at Dandenong until 1994."""
In [93]:
print(mainTextWiki)
Holden, formally known as General Motors Holden, is an Australian automobile importer and a former automobile manufacturer with its headquarters in Port Melbourne, Victoria. The company was founded in 1856 as a saddlery manufacturer in South Australia. In 1908 it moved into the automotive field, becoming a subsidiary of the United States-based General Motors (GM) in 1931, when the company was renamed General Motors-Holden's Ltd. It was renamed Holden Ltd in 1998, and General Motors Holden in 2005.

Holden sells the remaining stock of the locally produced range of Commodore vehicles, and imported GM models. Holden has offered badge engineered models in sharing arrangements with Chevrolet, Isuzu, Nissan, Opel, Suzuki, Toyota and Vauxhall Motors. In 2013 the vehicle lineup consisted of models from GM Korea, GM Thailand, GM in the US, and self-developed Commodore, Caprice, and Ute. Holden also distributed the European Opel brand in Australia in 2012 until the Opel brand's Australian demise in mid-2013.[1]

From 1994 to 2017, all Australian-built Holden vehicles were manufactured in Elizabeth, South Australia, and engines were produced at the Fishermans Bend plant in Melbourne. Historically, production or assembly plants were operated in all mainland states of Australia. The consolidation of car production at Elizabeth was completed in 1988, but some assembly operations continued at Dandenong until 1994.
In [95]:
rules={
    "html":"#head#<title>#title#</title>\n</head>\n\n#body#\n</html>",
    "head":htmlHead,
    "title":"this is the title",
    "body":"<body bgcolor=#hxn##hxn##hxn##hxn##hxn##hxn#>\n#pageDiv#\n#\n</body>",
    "pageDiv":"<div id=\"page\">\n<div id=\"header\">\n<ul>#pageTab##pageTab##pageTab##pageTab#</ul>\n<h1>#techNames#</h1>\n</div>#divDotLine#<div class=\"dotted_line\"></div>\n#footer#",
    "pageTab":"\n<li><a href=\"#link#\">#techNames#<a/></li>",
    "divDotLine":"<div class=\"dotted_line\"></div>\n<div id=\"main\">\n<div class=\"main_left\">\n<img scr=\"#imglink#\" alt=\"by #firstN# #lastN# at https://symbiosis.live\"/>\n<h1>#techNames# will save us</h1>\n<h3>in #techNames# you should have faith, #techNames# will save us all</h3>\n</div>\n#divmainR#",
    "divmainR":"<div class=\"main_right\">\n<h2>#firstN# #lastN# and #techNames#</h2>\n<p>#mainText#</p>\n</div>\n<div class=\"main_bottom\"></div>\n</div>\n",
    "footer":"<div id=\"footer\>\n<p>\n<a href=\"https://symbiosis.live#link#\"> website design. Contact: #email#\n#phone#.</a></p>\n</div>\n</div>",
    "hxn":['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'],
    "link":["/#routes#","/#routes#","/#routes#.#type#"],
    "imglink":["/#routes#","/#routes#","/#routes#.png"],
    "routes":["#route#","#route#-#route#","#route#/#route#/#route#"],
    "route":["#techNames#", "#techNames#","#techNames#","#routes#",],
    "type":["pdf","php","html","img","png","html","php"],
    "techNames":tech,
    "firstN":firstNames,
    "lastN":lastNames,
    "mainText":mainTextWiki,
    "phone":["#n##n##n#.#n##n##n#.#n##n##n##n#","#n##n##n# #n##n##n# #n##n##n##n#","#n##n##n#-#n##n##n#-#n##n##n##n#","(#n##n##n#)-#n##n##n#-#n##n##n##n#"],
    "n":["1","2","3","4","5","6","7","8","9"],
    "email":"#firstN.lowercase#.#lastN.lowercase#@#domain.lowercase#.#domainType#",
    "domain":tech,
    "domainType":["com","edu","io","cc","net","xyz","xxx","org","gov","ai","com","com","me"]
    
}
grammar=tracery.Grammar(rules)
grammar.add_modifiers(base_english)
file = open('index.html', 'w')
file.write(grammar.flatten("#html#"))
file.close()
print(grammar.flatten("#html#"))
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" /><title>this is the title</title>
</head>

<body bgcolor=1A3D99>
<div id="page">
<div id="header">
<ul>
<li><a href="/Drupal-Foursquare">GoogleDocs<a/></li>
<li><a href="/AppleScript-Rust">SQS<a/></li>
<li><a href="/CodePipeline/HacketyHack/ActiveRecord/Scheme/Diaspora-Tumblr">OpenCV<a/></li>
<li><a href="/Polymer/ImageMagick/NLTK/YouTube/Python-SpoonRocket">Bundler<a/></li></ul>
<h1>Flickr</h1>
</div><div class="dotted_line"></div>
<div id="main">
<div class="main_left">
<img scr="/Express-Bootstrap/Emacs/Diaspora" alt="by Braden Stevens at https://symbiosis.live"/>
<h1>PushNotifications will save us</h1>
<h3>in Webaudio you should have faith, Cucumber will save us all</h3>
</div>
<div class="main_right">
<h2>Skylar Kennedy and Solr</h2>
<p>Holden, formally known as General Motors Holden, is an Australian automobile importer and a former automobile manufacturer with its headquarters in Port Melbourne, Victoria. The company was founded in 1856 as a saddlery manufacturer in South Australia. In 1908 it moved into the automotive field, becoming a subsidiary of the United States-based General Motors (GM) in 1931, when the company was renamed General Motors-Holden's Ltd. It was renamed Holden Ltd in 1998, and General Motors Holden in 2005.

Holden sells the remaining stock of the locally produced range of Commodore vehicles, and imported GM models. Holden has offered badge engineered models in sharing arrangements with Chevrolet, Isuzu, Nissan, Opel, Suzuki, Toyota and Vauxhall Motors. In 2013 the vehicle lineup consisted of models from GM Korea, GM Thailand, GM in the US, and self-developed Commodore, Caprice, and Ute. Holden also distributed the European Opel brand in Australia in 2012 until the Opel brand's Australian demise in mid-2013.

From 1994 to 2017, all Australian-built Holden vehicles were manufactured in Elizabeth, South Australia, and engines were produced at the Fishermans Bend plant in Melbourne. Historically, production or assembly plants were operated in all mainland states of Australia. The consolidation of car production at Elizabeth was completed in 1988, but some assembly operations continued at Dandenong until 1994.</p>
</div>
<div class="main_bottom"></div>
</div>
<div class="dotted_line"></div>
<div id="footer>
<p>
<a href="https://symbiosis.live/Mocha"> website design. Contact: [email protected]
(163)-721-8312.</a></p>
</div>
</div>

</body>
</html>