I have some data in mongodb and would like to create an email which pulls data from the db and inserts it into some sort of (mustache/django'esque) email template and then sends it.
The data has been scraped from a website with articles and when new articles are retrieved I'd like to create a summary email of all the new articles from this particular site.
So far I've discovered premailer which looks like it will be useful for the necessary inline css. python-emails looks somewhat promising as well...
Surely it is a common task to create well formatted emails from data in a db using python? But surprisingly I haven't been able to find any specific information about how to do this.
EDIT: I just discovered this way of using django to generate emails from their templates. I'll investigate this further and update my question here once I find a functioning solution.
I don't think you need Django, you can use a templating engine like Jinja2 to create the email templates and inject data into them, then use smtplib to send the email.
Related
I'm querying a real estate API using Python (requests), with POST data submitted in JSON format.
I'm getting responses as expected - however each time I want to make a query I'm editing the fields in a hardcoded JSON object in the .py file.
I'd like to do something a bit more robust - eg using a user prompt to populate the JSON object to be submitted, based on the API search schema (see JSON file (pastebin)) (open to alternative python based solutions to this).
The linked schema includes the full list of parameters available to query - I'll likely trim this down to the ones that are most relevant to the queries that I'm building/POSTing, so that there are less parameters to deal with. I'd like to know of a Pythonic way to cycle through the Parameters in the Schema and then add the ones I wish to submit for a query to the JSON object?
TIA.
I am somewhat of a beginner at Python and I am currently starting some brainstorming and planning for a project to simplify the tedious task of filling out a product order form for a friend's business. I am wanting to create a program with an interface that takes in input and writes to an already existing pdf form of the physical order form. I would also like to implement being able to then email that form to another coworker and having accessible information of previous orders from the current customer ordering.
I am most curious about how to write to an already existing pdf form and just fill in the blanks, potentially using a PDF Reader? Also, for product catalog data and customer order history, would using dictionaries suffice or would it be better to use some python database?
I know I could figure out how to individually do each of those tasks but I don't know how to tie it all together properly to distribute it, either making a WebApp or an executable file from the script and just use tkinter or another GUI library for the interface, or if there is a more obvious and convenient option?
If I were to do a WebApp, what would be my best option, I've seen options such as Anvil, Flask, Django, and I just don't know what would be best for what I'm trying to accomplish.
I know this is a longshot and vague but any advice or guidance in the right direction would be much appreciated!
I'd go with a web app here. Personally, I prefer Django, and I don't think that it would be too difficult to learn it well enough for your purposes!
Regarding saving product catalog data and customer order history: I would definitely recommend using a database for your backend, which Django helps you do! Database integration is almost ridiculously easy using Django.
Here's some resources for the specific things you asked about:
Django vs. Flask
Working with HTML forms (Django) (this will help with taking user input)
filling an existing PDF form in Python (this will help with using user input to fill out the pdfs)
How to send email attachments in Python? (this will help you email your coworker the filled out pdf)
If you need more help/guidance, definitely feel free to follow up!
I have scraped data from a website using their API on a Django application. The data is JSON (a Python dictionary when I retrieve it on my end). The data has many, many fields. I want to store them in a database, so that I can create endpoints that will allow for lookup and modifications (updates). I need to use their fields to create the structure of my database. Any help on this issue or on how to tackle it would be greatly appreciated. I apologize if my question is not concise enough, please let me know if there is anything I need to specify.
I have seen many, many people saying to just populate it, such as this example How to populate a Django sqlite3 database. The issue is, there are so many fields that I cannot go and actually create the django model fields myself. From what I have read, it seems like I may be able to use serializers.ModelSerializer, although that seems to just populate a pre-existing db with already defined model.
Tricky to answer without details, but I would consider doing this in two steps - first, convert your json data to a database schema, for example using a tool like sqlify: https://sqlify.io/convert/json/to/sqlite
Then, create a database from the generated schema file, and use inspectdb to generate your django models: https://docs.djangoproject.com/en/2.2/ref/django-admin/#inspectdb
You'll probably need to tweak the generated schema and/or models, but this should go a long way towards automating the process.
I would go for a document database, like Elasticsearch or MongoDB.
Those are made for this kind of situation, look it up.
I am currently working on a project where the user wants the user interface to look like an Excel document. This is because the user normally writes data into an Excel document, and wants to switch to writing data straight into the user-interface instead. It should look something like this:
In this project, so far, I have only used Django, and there was no need for using Bootstrap, for example. However, I would be willing to use a front-end framework in order to create this Exel-like user interface. Trying to make html-tables have been unsuccessful so far.
Does anyone have suggestions on how it might be done?
Thank you!
Perhaps best thing to do first is to convince someone that the UI doesn't have to be like Excel.
Definitely worth consider gspread so that you don't get stuck in a complex relational structure.
See https://www.youtube.com/watch?v=vISRn5qFrkM and https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet-in-python.html
Django is basically for developing webapp .
You have to create model(default db) and then store your data there .
You should create a webapp and one of the html page should have the above tables and you should give your model data as input to your html page using django views
Django Version - 1.10.5
I have uploaded the file on MongoDB, with a few fields like e-mail, employee_id
and of course the file from an HTML page. I can see it in mongoDB. What I want to do is retrieve the data on an another HTML page using one of those fields(for example putting in a email id that was used to upload the article will give the entire article on the same HTML page.) . How do I go around that?
From my understanding of the question, current state is:
You have imported data to MongoDB
You want to retrieve some data into HTML
I didn't understand where you are stuck and hence simple steps would be to create your models.py file defining the fields that you mentioned, email_id, employee_id, etc. Check details on how
Django models API lets you create, retrieve, update and delete objects. Next topic in this documentation page.
I recommend reading through Django documentation thoroughly and trying out things in a demo app from here - Django Models and Databases
Extra: You could use raw SQL queries if you used SQL based DB. But Django quotes:
You should be very careful whenever you write raw SQL. Every time you use it, you should properly escape any parameters that the user can control by using params in order to protect against SQL injection attacks. Please read more about SQL injection protection.