I'm hoping someone can help (I'm new to python). I have created a text file with customer information.
The details that are being stored in the text file are "First Name, Last name, Telephone Number, and email address".
I wish to create a python program to read the file. However, before adding information from the file, I want to do validation checks.
How do I get Python to do a validation check on the data e.g. data entered is the correct data type?
There are many ways to check data in Python. What are you trying to validate?
Related
I want to write a small script in which I use data from an excel document and mix it with a text I have that I send to leads.
Example:
Hello (Data-Name), I can see that your business (Data-business) need
some service on (Data-website name). Best regards Jim
So if I have 100 leads, then, it must create a document for the data to be inserted into the text and create a new document with the generated text.
I have been trying this but I was not able to make it work.
I need to create emails with rich text format. Inside the email, it has a table, and under one column of the table, for each row, i need to attach different emails
Would above be achievable using python
Any help will be appreciated!
I feel like the title of this problem just made this whole thing even more confusing. But here is the long of it:
I have a bot that uses .JSON files to store information a user puts into it upon creation. However, to ensure that they are creating one, and only one, file, I have tied it to their unique ID. This ensures that even if a user changes nicknames, he can only create one file for himself. Of course, the .JSON file in the background, will be named '123456789.txt'.
This has been done successfully, but I want to add in bot commands that will allow OTHER users to obtain information stored in that user's file. So, for example: If Joe wants to see what Ned's favorite color is, he could use a simple command like:
!favcolor Ned
And the bot will fine Ned's .JSON file (123456789.txt), look for what value is stored under the key "color", and print out the results.
The problem isn't that I can't find people's user ID (ctx.message.author.id). The problem is that I don't know how to let someone else do such, as, as far as I can find out, there is no way to ensure that when someone precedes '!favcolor' with 'Ned', the bot will find 123456789.txt.
The only solution I can think of at the moment is to maintain a .JSON file at the moment of creation of a file that grabs the user's unique ID, and then pairs it with the name of the user. Something like:
{
"Ned": "123456789"
"Joe": "234567891"
"Sam": "345678912"
}
And so on. Then it just looks at that JSON, and grabs the correct ID. Is this a good approach? Or am I missing something much easier that is already built into discord.py?
Discord users are only uniquely identifiable by ID or username#discriminator.
You can easily get the ID from a User object, given that you're able to identify it from the user input in question.
A .JSON file with a .txt extension is contradictory, and you should be storing JSON data in JSON files rather than text files.
Also, I'd recommend using a database rather than JSON files, as there are lot of advantages to doing so and a lot of disadvantages to continuing to use JSON files.
I'm trying to store user data for a website in Python I'm making. Which is more efficient:
-Storing all the user data in one huge table
-Storing all the user data in several tables, one per user, in one database.
-Storing each user's data in a XML or JSON file, one file per user. Each file has a unique name based on the user id.
Also, which is safer? I'm biased towards storing user data in JSON files because that is something I already know how to do.
Any advice? I'd post some code I already have, but this is more theoretical than code-based.
I don't think efficiency should be part of your calculus.
I don't like either of your proposed designs.
One table? That's not normalized. I don't know what data you're talking about, but you should know about normalization.
Multiple copies? That's not scalable. Every time you add a user you add a table? Sounds like the perfect way to ensure that your user population will be small.
Is all the data JSON? Document based? Maybe you should consider a NoSQL document based solution like MongoDB.
I'm doing a bit of an experiment in Python. I'm making a script which checks a rss-feed for new items, and then sends the title and link of the items via email. I've got the script to work to a certain level: when it runs it will take the link+title of the newest item and email it, regardless of wether it emailed that file already or not. I'd need to add 2 things: a way to get multiple items at once (and email those, one by one), and a way to check wether they have been sent already. How would I do this? I'm using feedparser, this is what I've got so far:
d = feedparser.parse('http://feedparser.org/docs/examples/rss20.xml')
link = d.entries[0].link
title = d.entries[0].title
And then a couple of lines which send an email with "link" and "title" in there. I know I'd need to use the Etag, but haven't been able to work out how, and how would I send the emails 1 by 1?
for the feed parsing part, you could consider following the advise given in this question regarding How to detect changed and new items in an RSS feed?. Basically, you could hash the contents of each entry and use that as an id.
For instance, on the first run of your program it will calculate the hash of each entry, store that hash, and send these new entries by mail. On it's next run, it will rehash each entry's content and compare those hashes with the ones found before (you should use some sort of database for this, or at least an on memory dictionary/list when developing with the entries already parsed and sent). If your program finds hashes that where not generated on the previous runs, it will assemble a new email and send it with the "new" entries.
As for your email assembling part, the question Sending HTML email in Python could help. Just make sure to send a text only and a html version.
For the simplest method see the python smtplib documentation example. (I won't repeat the code here.) It's all you need for basic email sending.
For nicer/more complicated email content also look into python's email module, of course.