Rename system folder using sql query in python - python

I have made a power automate flow that runs when someone submit a Microsoft form, the result will create a folder of the name of the person who filled that form (Name field is mandatory in the form) and store the files into that folder he has attached at the time of filling the form. Names also gets updated in the database under xyz table. It is sure that if 10 people fill the form in a day then in database also there will be 10 rows added under Name column.
In xyz table there is one more column named surname. It also gets updated along with name column.
example below:
Name Surname
David Warner
Shane Watson
What I want is to make a python script that check names from the database daily and change folder names to surname. Basically, the script will check if name = David then changes the folder name to Warner and if name = Shane then changes it to Watson and so on... I have no idea how to rename like this.

Actually it makes your work hard when some names may be duplicated and folder names can't be. I recommend you to use sth like unique primary key as auto increment and make folder for every id of users. In such case you don't need to change anything. It is a little bit hard to find out files but it is easy to implement.
Another way to implement sth like this is to structure folder based on Year/Month/Day of creation. This is organized and you can store the file path as another field in DB and easily access them.

Related

Is there a way to fetch the author's name of a Sharepoint file in Python?

I want to get the author's name (Created By/Modified By) of several files contained in a Sharepoint folder in Python.
I have used the Shareplum library to connect to the site and was able to retrieve some details (for ex- Time Modified/ Time Created) about the files but not the name of the author who has added the file. Is there any way to do so?
You have to use the internal name of columns in API calls to get the column values from SharePoint list.
Below are internal names for created by and modified by columns:
Created By: Author
Modified By: Editor
Use these column names in your API call along with "Created" and "Modified (which fetches dates) to get the Created By and Modified By values on files.

data base or text file and excel file in Django

if you have some fixed data in Django, for example, ten rows and 5 columns.
Is it better to create a database for it and read it from the database, or is it not good and it is better to create a dictionary and read the data from the dictionary?
In terms of speed and logic and ...
If the database is not a good choice, should I write the data as a dictionary in View Django or inside a text file or inside an Excel file?
Whichever method is better, please explain why.
It depends upon the application.. but if there is doubt, create a model for it and put it in the database. And here's why I say that:
If your data needs to be changed, or if you want to view it, you can easily do so in the Django Admin app.
If your applications contains models which relate to this data, you can use a foreign key to reference it, rather than replicating it or using references that aren't enforced by the database.
It makes it much easier to do queries on your whole database if everything is in the database. For example, let's say that you have a table of "houses" and each house has a "color".. but you've stored the list of color names in a dictionary outside the database. Now you want a list of houses that are "Bright Blue". First you have to look in your dictionary to find the id of the color "Bright Blue", then you have to do your database lookup using the id you found. It takes something that would normally be a very simple one-line query in Django and makes it much harder.
By the same logic, if you wanted a list of houses along with their color, this would be a very simple query if done entirely in the database but is extra work if you keep some data elsewhere.

Django: is it good to have a model with more then 60 fields? And best way to develop project

I'm working on my first project in Django and I'd really like to have some advice from people with more experience then me since right now I'm a little stuck on what road take to keep developing my project.
This is my plan to develop my project:
Create a modelsFileFields so that my user can upload one or more standarded excel file
Read it and create variables with pandas
Create an html page with the graph with chart.js and render it in pdf with ReportLab
Store the pdf in my user profile usinig primary key so that they can see it and download it again.
My main problem right now is to store or not the information that are in the excel file in my database. Since getting the information in the excel file is what is important to me, my first thought was to import them and the only thing that it keeping me from doing so is the quantity of column that I have. This how my excel file looks like:
total partial [...]
user1 10 4
user2 18 6
I have more then 60 variable in my excel file (so I'd need a model with more then 60 fields) and they should be doubled since I'd need the information from user1 and also user2.
So I'd like to ask if I should give up on import the csv to my database since how much big it would be and also if what I'm plannning to do has sense or if there is a better way to do so (every exemple project is welcomed).
Thanks for the helps!

Generic data handling in Python

The situation
While reading the Bible (as context) I'd like to point out certain dependencies e.g. of people and locations. Due to swift expandability I'm choosing Python to handle this versatile data. Currently I'm creating many feature vectors independent from each other, containing various information as the database.
In the end I'd like to type in a keyword to search in this whole database, which shall return everything that is in touch with it. Something simple as
results = database(key)
What I'm looking for
Unfortunately I'm not a Pro about different database handling possibilities and I hope you can help me finding an appropriate option.
Are there possibilities that can be used out of the box or do I need to create all logic by myself?
This is a little vague so I'll try to handle the People and Location bit of it to help you get started.
One possibility is to build a SQLite database. (The sqlite3 library + documentation is relatively friendly). Also here's a nice tutorial on getting started with SQLite.
To start, you can create two entity tables:
People: contains details about every person in bible.
Locations: contains details about every location in bible.
You can then create two relationship tables that reference people and locations (as Foreign Keys). For example, one of these relationship tables might be
People_Visited_Locations: contains information about where each person visited in their lifetime. The schema might looks something like this:
| person (Foreign Key)| location (Foreign Key) | year |
Remember that Foreign Key refers to an entry in another table. In our case, person is an existing unique ID from your entity table People, location is an existing unique ID from your entity table Locations, and year could be the year that person went to that location.
Then to fetch every place that some person, say Adam in the bible visited, you can create a Select statement that returns all entries in People_Visited_Locations with Adam as person.
I think key (pun intended) takeaway is how Relationship tables can help you map relationships between entities.
Hope this helps get you started :)

Outlook automation / Object Model query (Python) - unique ID for each email?

I've been using the MSDN to build a simple app that automates some Outlook 2010 basics.
It's going well, but I'm just stuck at something simple I think.
My question is this:
I've been able to get objects based on email folders, and even emails, and iterate through them, outputting email subjects as strings, or folder names as strings.
I've been able to get the info into listboxes, but I'm wondering, let's say I want to do something with a specific email I have selected in a listbox, does anybody know if the mailitem object has a property like a unique ID that I could have hidden somewhere or in a SQLite DB that I could use as a reference to do something with said email instead of having to search through the folder again by subject or name ?
The same question kinda applies to what I'm doing to find a specific folder, looping through the inbox folder and if I find the folder by name, then output that folder object. Surely there's a more efficient way to search by name in one step, without looping through folders to find subfolders etc ?
This isn't necessarily a python question, more about how the objects work.
Any help is much appreciated
MSDN Links:
Outlook Object Model Reference
http://msdn.microsoft.com/en-us/library/office/ff870566%28v=office.14%29.aspx
Folders Object
http://msdn.microsoft.com/en-us/library/office/ff870798%28v=office.14%29.aspx
Items Object
http://msdn.microsoft.com/en-us/library/office/ff870897%28v=office.14%29.aspx
MailItem Object
http://msdn.microsoft.com/en-us/library/office/ff870912%28v=office.14%29.aspx
You are probably looking for EntryID.
But please be aware that this ID is only unique/constant per .pst file.

Categories