#!/usr/bin/env python # coding: utf-8 # ### 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#") # ### [Corpora first Names](https://github.com/dariusk/corpora/blob/master/data/humans/firstNames.json) # In[16]: import json # In[33]: first_names= json.loads((open("text_examples/CorporaFirstNames.json").read())) # ### [Corpora Last Names](https://github.com/dariusk/corpora/blob/master/data/humans/lastNames.json) # 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#") # 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#")) # ### 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#")) # In[60]: htmlHead="\n\n\n" # In[61]: print (htmlHead) # 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) # In[95]: rules={ "html":"#head##title#\n\n\n#body#\n", "head":htmlHead, "title":"this is the title", "body":"\n#pageDiv#\n#\n", "pageDiv":"
\n
\n\n

#techNames#

\n
#divDotLine#
\n#footer#", "pageTab":"\n
  • #techNames#
  • ", "divDotLine":"
    \n
    \n
    \n\"by\n

    #techNames# will save us

    \n

    in #techNames# you should have faith, #techNames# will save us all

    \n
    \n#divmainR#", "divmainR":"
    \n

    #firstN# #lastN# and #techNames#

    \n

    #mainText#

    \n
    \n
    \n
    \n", "footer":"
    \n

    \n website design. Contact: #email#\n#phone#.

    \n
    \n
    ", "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#")) # In[ ]: