Shinyshell Community Forums > Coding > Python... |
||||||
Sign Up | Member List | New Posts | Help |
[1]
April 20 02009, 06:33 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
Okay, seeing as I can't catch you over IM, here's what I'm having trouble with:
First, time stamps - how do I convert them to a readable and understandable format? Second, what can I use as a Python alternative to PHP's "nl2br" function? Next, how do I send e-mails from within a script? For instance, if I wanted to an e-mail to myself to alert me of the latest error report? Finally, what would be the best way to code a search function? Thannnk you. If you hadn't read my latest update, I've decided to finish the features first, and then the content and layouts :D YAY ______________________________ Lazurane |
April 21 02009, 21:01 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
Timestamps
I believe I provided you with the timeformat() function (it should be among the generic functions like unicode_safe() and htmlspecialchars(). The first parameter is a formatting string (much like PHP's date() or gmdate() function that you might already be familar with). The format characters are slightly different though - they're in the table on this page. So, for example, to print out "April 21 2009, 22:16", call the timeformat function with the following parameters: ("%B %d %Y, %H:%M", time.time() ) nl2br The nl2br function just inserts a <br /> before any newlines in the provided string. Newlines are "\n" characters. You could just use the replace() method of string objects: text = "your text with newline chars\nWoop!" Sending email There's a cute little library for sending mail over SMTP - smtplib. Combine this with the MIMEText object from the email lib. Here's a demonstration import smtplib You need to specify an SMTP server. Mail.eeveeshq.com might work while Kat hosts you. I haven't tested this yet. Search It's probably best to add a row called "tags" to content like articles and news entries. Then users can search by this keyword (you can actually list them). Otherwise, since your database isn't going to be lord knows how large, I recommend just using SQL's LIKE condition to search content fields. Do this for every table you think is relevant, and list out the results if anything was found. SELECT * FROM articles I also recommend making a list of keywords that don't get searched for, stuff like "a, the, most, I, be, ..." - you get the drift. |
April 22 02009, 11:22 GMT | ||||
Nick^ merciful justice Location: Brisbane, Australia Post count: 78 |
Thanks for all that.
Timestamps However, there's an error with your timeformat function: said nl2br Working great, thank you. I've made my own linebreaks() function and everything! Sending emails Eurgh not working...! D: The e-mail sends, and I receive it, but the e-mail is blank, with an attachment named "noname" (probably gmail's doing), which contains the message (which contains %s as opposed to the actual variable). ______________________________ Lazurane |
April 23 02009, 10:48 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
Timestamps
That's because the second argument has to be a float, as that error states. You're passing a string: time = electron.misc.timeformat("%B %d %Y, %H:%M", '1240146898.6104') it should be: time = electron.misc.timeformat("%B %d %Y, %H:%M", 1240146898.6104) A quick fix for this would be just to call the float() function on the second argument. nl2br Great :) Sending emails Hmm, I'm not sure exactly why that is happening. My guess is that you're not specifying a MIME-type for the attached document (text/plain or text/html) so Gmail isn't showing it as the contents. I'll check this out a little more, I guess you should experiment with it a little, see if you can get it working before then. |
[1]
Forum Information |
||||||||||
|