grabbing the file description from details tab - python

I want to be able to grab the File description string from the details tab on a .dll or a .sys file. I've tried to do this in a number of methods, but can't get them to click. Is there anyway to do this through the command line to get it to produce an output to the screen. I've had no joy with FileVersion.description that is available using VB.
Any direction or help would be much appreciated here.
Thanks

langs = win32api.GetFileVersionInfo(ExecutablePath, r'\VarFileInfo\Translation')
key = r'StringFileInfo\%04x%04x\FileDescription' %(langs[0][0], langs[0][1])
print (win32api.GetFileVersionInfo(ExecutablePath, key))

As a starting point it looks like some of this stuff can be retrieved using win32api. You can find documentation here, and of course using python's built-in help().
I edited to add some code to show how some of the information can be retrieved. I've used win32api as well as os.stat Hope this is enough to get you started. Shouldn't be too hard to find the rest of it with what I've given so far.
import os
import time
import stat
from win32api import GetFullPathName
def get_details(file_name):
time_format = "%m/%d/%Y %I:%M:%S %p"
file_stats = os.stat(file_name)
return {
'folder_path': GetFullPathName(file_name),
'size': file_stats[stat.ST_SIZE],
'date_modified':time.strftime(time_format,time.localtime(file_stats[stat.ST_MTIME])),
'access_time': time.strftime(time_format,time.localtime(file_stats[stat.ST_ATIME])),
}
print get_details("myfilename")

Related

python 3 - functions exercise download an image (import urllib.request + random)

Python 3, functions.
There is the following exercise:
In this exercise, we will write code that allows us to
download an image from the web! We will use an external module and understand how to read the documentation of the functions and use them.
We want to write a function that accepts a photo Url and
downloads the photo to your computer.
You can choose any picture you want from the Internet by clicking the right button and selecting "Copy Image Url”.
the image I chose:
https://images.theconversation.com/files/377569/original/file-20210107-17-q20ja9.jpg?ixlib=rb-1.1.0&rect=278%2C340%2C4644%2C3098&q=45&auto=format&w=926&fit=clip
the wanted name:
"4.jpg"
the given instructions:
Write code that selects a random number between 1 and 1000. The number will be the file name (search how to select a random number in python).
The image name has to have the right suffix, so concat“.png" to the end of the number you selected (You can also use .jpg, .bmp, etc).
For example: if the selected number was 2T0, you should have a variable that holds the string: “270.png”.
Import module urllib.request: https://docs.python.org/3/library/urllib.request.html#module-urllib.request
Read "how to use the urlretrieve function":
http://shecodesconnect.com/shecodes_python_blog/urlretrieve_en.php?lang=%27en%27
Use the function you read about in order to
download the image and save it under the name
you prepared.
Run the code you wrote and check the folder where your code is saved if the image was downloaded!
my code that doesn't work:
import urllib.request
local_filename, headers = urllib.request.urlretrieve(https://images.theconversation.com/files/377569/original/file-20210107-17-q20ja9.jpg?ixlib=rb-1.1.0&rect=278%2C340%2C4644%2C3098&q=45&auto=format&w=926&fit=clip)
html = open(local_filename)
html.close()
headers.items()
headers["content-type"]
image_url="https://images.theconversation.com/files/377569/original/file-20210107-17-q20ja9.jpg?ixlib=rb-1.1.0&rect=278%2C340%2C4644%2C3098&q=45&auto=format&w=926&fit=clip.jpg"urllib.request.urlretrieve(url=image_url, filename="4.jpg")
import random()
a=random.randint(1,1000)
print(4)
Hope you could help, my code doesn't work, thank you in advance!
After fixing the errors, looks like you end up with the below:
import urllib.request
local_filename, headers = urllib.request.urlretrieve('https://images.theconversation.com/files/377569/original/file-20210107-17-q20ja9.jpg?ixlib=rb-1.1.0&rect=278%2C340%2C4644%2C3098&q=45&auto=format&w=926&fit=clip')
html = open(local_filename)
html.close()
headers.items()
headers["content-type"]
image_url="https://images.theconversation.com/files/377569/original/file-20210107-17-q20ja9.jpg?ixlib=rb-1.1.0&rect=278%2C340%2C4644%2C3098&q=45&auto=format&w=926&fit=clip.jpg"
urllib.request.urlretrieve(url=image_url, filename="4.jpg")
import random
a=random.randint(1,1000)
print(4)
Assuming the code in the question is what were you were able to come up with, that is.

How do I press alt <numpad> with pyautoguii?

Here's my script:
import pyautogui
import subprocess
import time
#notepad is in the file path
programma = "Notepad"
#opening notepad
subprocess.Popen(programma)
#gives time to open notepad, ie I've also tried with higher numbers
time.sleep(1)
pyautogui.keyDown('NumLock')
#I've also tried with
pyautogui.hotkey('alt', 'num3')
I've tried and the Numpad works: if I comment the take out 'alt' and just write
pyautogui.press('num3')
it types the number 3.
Although if I put alt in the code, it gives an error, as if I were typing without having the cursor set.
I've also tried
pyautogui.keyDown('alt')
pyautogui.keyDown('num3')
pyautogui.keyUp('num3')
pyautogui.keyUp('alt')
Does anyone know what to do?
Thanks in advance
Working for me:
pyautogui.keyDown('alt')
pyautogui.press("num3")
pyautogui.keyUp('alt')
If you try to .keyDown('num3') pyautogui will think you want to use a third key in your combination.

When I run the code, it runs without errors, but the csv file is not created, why?

I found a tutorial and I'm trying to run this script, I did not work with python before.
tutorial
I've already seen what is running through logging.debug, checking whether it is connecting to google and trying to create csv file with other scripts
from urllib.parse import urlencode, urlparse, parse_qs
from lxml.html import fromstring
from requests import get
import csv
def scrape_run():
with open('/Users/Work/Desktop/searches.txt') as searches:
for search in searches:
userQuery = search
raw = get("https://www.google.com/search?q=" + userQuery).text
page = fromstring(raw)
links = page.cssselect('.r a')
csvfile = '/Users/Work/Desktop/data.csv'
for row in links:
raw_url = row.get('href')
title = row.text_content()
if raw_url.startswith("/url?"):
url = parse_qs(urlparse(raw_url).query)['q']
csvRow = [userQuery, url[0], title]
with open(csvfile, 'a') as data:
writer = csv.writer(data)
writer.writerow(csvRow)
print(links)
scrape_run()
The TL;DR of this script is that it does three basic functions:
Locates and opens your searches.txt file.
Uses those keywords and searches the first page of Google for each
result.
Creates a new CSV file and prints the results (Keyword, URLs, and
page titles).
Solved
Google add captcha couse i use to many request
its work when i use mobile internet
Assuming the links variable is full and contains data - please verify.
if empty - test the api call itself you are making, maybe it returns something different than you expected.
Other than that - I think you just need to tweak a little bit your file handling.
https://www.guru99.com/reading-and-writing-files-in-python.html
here you can find some guidelines regarding file handling in python.
in my perspective, you need to make sure you create the file first.
start on with a script which is able to just create a file.
after that enhance the script to be able to write and append to the file.
from there on I think you are good to go and continue with you're script.
other than that I think that you would prefer opening the file only once instead of each loop, it could mean much faster execution time.
let me know if something is not clear.

Connecting to a part of a website depending on input. Python

Im new to python and wondering if there is a way for it to open a webpage depending on whats been inputted. EG
Market=input("market")
ticker=input("Ticket")
would take you to this part of the website.
https://www.tradingview.com/symbols/'market'-'ticker'/technicals
Thanks
Looks like you were pretty much there, but it python you can use the + sign to concatenate strings and then cause it to open that link using webbrowser library
import webbrowser
market=input("market")
ticker=input("Ticket")
webbrowser.open('https://www.tradingview.com/symbols/'+market+'-'+ticker+'/technicals')
Its cleaner to use format string like this:
import webbrowser
market=input("market")
ticker=input("Ticket")
webbrowser.open(f'https://www.tradingview.com/symbols/{market}-{ticker}/technicals')

Import Skin Weight Maps (Python) - (Maya)

Like mentioned on this post, I would like to just import a skin weightmap (a .weightMap file) into a scene without having to open a dialogue box. Trying to reverse - engineer the script mentioned in the reply didn't get me anywhere.
When I do it manually thru maya's ui - the script history shows...
ImportSkinWeightMaps;
...as a command. But my searches on this keep leading me to the deformerWeights command.
Thing is, there is no example on the documentation as to how to correctly write the syntax. Writing the flags, the path thru trial and error with it didn't work out, plus additional searches keep giving me the hint that I need to use a .xml file for some reason? when all I want to do is import a .weightMap file.
I even ended up looking at weight importer scripts in highend3d.com in hopes at looking at what a proper importing syntax should look like.
All I need is the correct syntax (or command) for something like:
mel.eval("ImportSkinWeightMaps;")
or
cmds.deformerWeights (p = "path to my .weightMap file", im=True, )
or
from pymel.core import *
pymel.core.runtime.ImportSkinWeightMaps ( 'targetOject', 'path to .weightMap file' )
Any help would be greatly appreciated.
Thanks!
why not using some cmds.skinPercent ?
It is more reliable.
http://tech-artists.org/forum/showthread.php?5490-Faster-way-to-find-number-of-influences-Maya&p=27598#post27598

Categories

Resources