Author Topic: I need a new approach  (Read 5972 times)

0 Members and 1 Guest are viewing this topic.

Offline Uriah

  • Sir
  • ***
  • Posts: 454
  • Cookies: 42
  • άξονας
    • View Profile
I need a new approach
« on: November 18, 2012, 12:44:42 am »
Some of you guys may have seen that python program I wrote to create a Home page based off of criteria. I'm trying to add to it and allow for the user to to decide the length of the search bar and the amount of line breaks between each element of the page. Right now they can only choose fonts, background images and colors, words displayed, and colors.
The problem with me allowing positioning is that I can't just set in a variable, because line breaks and etc. are not set by names, but my quantity, if that makes sense.
I can do an a trillion if else and else if statements, each writing a completely different html code based off of an input, but that would be a little too much.
Here's the code:
Code: [Select]
# File name: Ez.py


# Criteria Query:


print("Welcome! Please insert the required criteria to create your own, custom homepage!")
print("1.Title?")
T = raw_input(" ")
print("2.Header? ")
H = raw_input(" ")
print("Header Font Style?")
HFS = raw_input(" ")
print("Text Color?")
HTC = raw_input(" ")
print("3.Search Text? ")
ST = raw_input(" ")
print("4.Search Button Text?")
SBT = raw_input(" ")
print("5.Background Image?(Please name a valid PING or JPEG file.)")
BI = raw_input(" ")
print("6.Words on Page?")
WP = raw_input(" ")
print("Font Style?")
PFS = raw_input(" ")
print("Text Color?")
PTC = raw_input(" ")


# Status report to the user:
print("Website has been created!")
print(T, H, HFS, HTC, ST, SBT, BI, WP, PFS, PTC)
print("Now, just drag the 2 new files on your desktop into a folder that includes your background image!")
raw_input("Press ENTER to quit. ")


# Creating the hypertext mark up language:
X = open("Homepage.html", "wb")
X.write( """
<!doctype html>
<html>
<title>"""+T+"""</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"Homepage.css\" />
<body>
<center>
<h1>"""+H+"""</h1>
<br />
<form method=\"get\" action=\"http://www.google.com/search\">
<input onfocus="this.value=\'\'\" type=\"text\"   name=\"q\" size=\"45\"
 maxlength=\"255\" value=\""""+ST+"""\" />
<input type=\"submit\" value=\""""+SBT+"""\" />
</form>
<br /><br /><br /><br /><br />
<div id=\"Main\">
<h3>"""
+WP+
"""</h3>
<>
</center>
</body>
</html>
""");
X.close()




# Creating the cascading style sheet:
Y = open("Homepage.css", "wb")
Y.write("""
h1{
    color: """ +HTC+ """;
    font-family: """ +HFS+ """;
}
 
body{
    background: url("""+BI+""");
    background-attachment: fixed;
    background-position: 27% 27%;
}
h3{
    color:""" +PTC+""";
    font-family:""" +PFS+""";
}
}""");
Y.close()


#End.

Any ideas?
« Last Edit: November 18, 2012, 12:46:11 am by Uriah »

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: I need a new approach
« Reply #1 on: November 18, 2012, 08:57:17 am »
I don't really understand the problem, but would like to suggest to follow the Settings flowchart from Android devs when making settings for the user: http://developer.android.com/design/media/settings_flowchart.png

Offline s3my0n

  • Knight
  • **
  • Posts: 276
  • Cookies: 58
    • View Profile
    • ::1
Re: I need a new approach
« Reply #2 on: November 18, 2012, 02:33:20 pm »
I also don't really understand what you mean but you can just multiply "<br />" by a needed amount ;)

Code: (python) [Select]
breaks = int(raw_input("Enter the amount of line breaks: "))

fp.write(previous_html + "<br />"*breaks + remaining_hml)

fp.close()
Easter egg in all *nix systems: E(){ E|E& };E

Offline Uriah

  • Sir
  • ***
  • Posts: 454
  • Cookies: 42
  • άξονας
    • View Profile
Re: I need a new approach
« Reply #3 on: November 18, 2012, 09:56:55 pm »
I also don't really understand what you mean but you can just multiply "<br />" by a needed amount ;)

Code: (python) [Select]
breaks = int(raw_input("Enter the amount of line breaks: "))

fp.write(previous_html + "<br />"*breaks + remaining_hml)

fp.close()
Ahh, yes this is what I need. Thanks, both of you guys.