MoonPoint Support Logo

 


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
August
Sun Mon Tue Wed Thu Fri Sat
   
24 25 26
27 28 29 30 31    
2017
Months
AugSep
Oct Nov Dec


Wed, Aug 23, 2017 11:36 pm

Determining a file's type from within a Python script

I needed a way to determine a file's type within a Python script when I can't rely on the file's extension to determine the file format. I'll be running the script on a MacBook Pro laptop running the OS X El Capitan operating system. OS X/macOS, like Linux, comes with the file command, so I could run that command at a shell prompt to have the utility check the magic number in the files I'm interested in, but I want to do some additional processing of the files within the Python script, so I want to perform the format check within Python. Python provides the subprocess module that provides the capability to "spawn new processes, connect to their input/output/error pipes, and obtain their return codes." So I can call the file utility from within Python using that module. To get the results from running a shell command, you use suprocess.Popen(). You can then set a variable to hold the results of .communicate() and print the contents of that variable as shown below. The script expects the name of the file to be checked to be provided as an argument on the command line.

#!/usr/bin/python

import subprocess as sub, sys

try:
   sys.argv[1]
except IndexError:
   print "Error - missing input file name! Usage ./filetype.py infile"
   sys.exit(1)
else:
   fileName = sys.argv[1]

p = sub.Popen(['file',fileName],stdout=sub.PIPE,stderr=sub.PIPE)
output, errors = p.communicate()
print output

[ More Info ]

[/languages/python] permanent link

Tue, Aug 22, 2017 11:18 pm

Signing out of Amazon on a system with a low resolution display

Sometimes I encounter difficulties signing out of an account on Amazon's website when I need to sign into another account, if the resolution of the display isn't great enough to allow me to see the bottom of Amazon's list of choices where the sign out option appears. If I need to logon on such a system, there's no problem. If I visit Amazon's home page, I can click on "Hello. Sign in Accounts & Lists" where I see a "Sign in" button.

Amazon account and lists

[ More Info ]

[/network/web/shopping] permanent link

Mon, Aug 21, 2017 11:15 pm

Find all occurrences of a string in a file using Python

I need to download and view Excel workbooks, Portable Document Format (PDF), and sometimes other types of documents related to work requests from a website. When I view a webpage for a particular work request, some of the documents may have been posted weeks or months ago while some are more recent, but when I download them they all get the timestamp of the time I downloaded them, but I would like to change the timestamps to match the timestamps on the website. On the webpage for a particular work request, I see the following information for files:

Type Name Site Modified Modified By
xlsm icon CRQ000000884164_PDSO -None- 3/6/2017 4:53 PM Smith, Gary
pdf icon CRQ000000884164_PDSO -None- 3/6/2017 4:52 PM Smith, Gary
pdf icon CRQ000000884164_DCS -None- 6/12/2017 9:29 AM Doe, Mike
xlsm icon CRQ 884164_SDP -None- 6/12/2017 9:30 AM Doe, Mike

[ More Info ]

[/languages/python] permanent link

Sun, Aug 20, 2017 10:05 pm

Remotely Restarting Windows Services or Systems

After a power outage, I found I was unable to connect to a Microsoft Windows 10 system from a Windows Server 2012 system on the local area network (LAN) using the Remote Desktop Protocol (RDP). When I tried to connect, I saw the message "Remote Desktop can't connect to the remote computer for one of these reasons..."

Remote Desktop Connection - can't connect

I knew the system had rebooted after the power outage, because I could ping it and see its shared folders using the command net view systemName where systemName is the system's name.

[ More Info ]

[/os/windows] permanent link

Fri, Aug 18, 2017 10:41 pm

Importing data from a text file into an SQLite database with Python

I need to track work requests that are associated with particular projects. The work requests are submitted through a website, but I want to be able to run queries on the data that aren't available to me from the website. So I decided to add a projects table to an existing SQLite database I have on my MacBook Pro laptop. I didn't want to manually enter a list of about 200 projects into the table, however, so I copied the projects list from the website into a text file. The webpage that lists all of the projects includes projects that are no longer valid and I want to include those in my database table, but note that they are longer valid. When I copy the data from the web page, I have lines like the following ones:

450 SN/GN Tech  Edit Delete
ACE     Edit Delete
ADO     Edit Undelete
AGO     Edit Delete
AGS     Edit Delete
AIM     Edit Delete
Artemis         Edit Undelete
ASF     Edit Delete
ATSC    Edit Undelete
AXAF    Edit Undelete
BATSE/Gro       Edit Undelete
CANDOS  Edit Undelete
CARA    Edit Delete
CD Manager      Edit Delete
CMF     Edit Undelete
CMOC    Edit Delete
CMS     Edit Undelete

The entries that are no longer valid have "Undelete" at the end of the line indicating the projects were deleted, but they can be undeleted.

I created a table in the database with the following columns all of which contain text data:

NameDescription AddedRemoved DeletedNotes

[ More Info ]

[/languages/python] permanent link

Thu, Aug 17, 2017 11:09 pm

Obtaining information on a system's motherboard with PowerShell

You can obtain information on the motherboard in a computer running Microsoft Windows using PowerShell by means of the Get-Ciminstance cmdlet with the command Get-Ciminstance Win32_Baseboard. E.g., the following example is from a Microsoft Windows 10 system.

PS C:\> get-ciminstance win32_baseboard


Manufacturer : Gigabyte Technology Co., Ltd.
Model        :
Name         : Base Board
SerialNumber :
SKU          :
Product      : GA-78LMT-S2P



PS C:\>

The manufacturer, model number, serial number, SKU, and product number will be displayed if that information can be queried from the motherboard. Note: not all parameters will be available for every motherboard as shown above. For another system, the serial number is available.

PS C:\> get-ciminstance win32_baseboard


Manufacturer : Dell Inc.
Model        :
Name         : Base Board
SerialNumber : .7XCTZ12.CN7016346F0331.
SKU          :
Product      : 088DT1



PS C:\>

You can restrict the displayed information to particular parameters by piping the output to select-object. E.g.:

PS C:\> get-ciminstance win32_baseboard | select-object manufacturer

manufacturer
------------
Gigabyte Technology Co., Ltd.


PS C:\> get-ciminstance win32_baseboard | select-ojbect manufacturer, product

manufacturer                  product
------------                  -------
Gigabyte Technology Co., Ltd. GA-78LMT-S2P


PS C:\>

Another command line alternative to using PowerShell is to use WMIC to determine motherboard information.

[/os/windows/PowerShell] permanent link

Wed, Aug 16, 2017 10:59 pm

Recovering a Comic Life file

My wife uses Comic Life 3 from Plasq. On a couple of occasions recently, when she was using the program on one Microsoft Windows 10 system while editing a Comic Life file stored on another Windows 10 system, when she tried to save the file over the local area network (LAN) to the other system, she saw "Finalizing Save. Please Wait." but the save operation didn't complete.

Comic Life 3 finalizing save

After a long period of time had gone by, I finally rebooted the system on which Comic Life was running, since I couldn't kill it with the Windows Task Manager. Fortunately, all of her work was not lost, however. When I checked the system on which the Comic Life file was stored, I saw a file with a comiclife.latest extension in addition to the one with the .comiclife extension Comic Life uses for files.

C:\> dir "C:\Users\Public\2017\08\2017-08-18\*comiclife*"
 Volume in drive C has no label.
 Volume Serial Number is 5C60-1B61

 Directory of C:\Users\Public\2017\08\2017-08-18

08/15/2017  12:34 PM        40,099,848 Week33.comiclife
08/15/2017  12:51 PM        48,691,208 Week33.comiclife.latest
               2 File(s)     88,791,056 bytes
               0 Dir(s)  2,766,325,518,336 bytes free

C:\>

I moved the file with the .comiclife extension to another directory and renamed the Week33.comiclife.latest file to Week33.comiclife - I received the normal warning Windows displays when changing a filename extension, but proceeded.

Warning for changing file extension

I was then able to open the renamed file in Comic Life and recover the latest changes she had made to the file. This is the second time I've had to go through this process to recover her work in Comic Life due to Comic Life not completing the "finalizing save" step, but the incidences may have been due to a network issue.

[/software/comics/comiclife] permanent link

Tue, Aug 15, 2017 10:07 pm

Saving an email message to a file in mutt

Mutt is a text-based email client for Linux and Unix-like systems. If you want to save a particular message to a file in mutt, you can select the message then hit the v (the lowercase letter) key. In mutt, the letter is used for "view-attachments", but you can also use it to save the body of an email message to a file. If you hit the s key with the message selected or while viewing the message, you will see "<no description>" next to the number 1. If the email has any attachments they will be numbered from 2 upwards. With the first entry, i.e. the one labeled "<no description>" selected, if you hit the letter s (lowercase letter), you will see "Save to file:"

Mutt - save to file

Type the file name you wish the message to be saved under after "Save to file:" After saving the file, you can hit q several times to get back to the shell prompt. The message will be in the current directory. The file will only contain the contents of the message, not the message header, i.e., you won't see from, to, and subject lines.

[/network/email/clients/mutt] permanent link

Sun, Aug 13, 2017 10:24 pm

Symantec OCSP - gn.symcd.com

I opened HTTPNetworkSniffer, a packet capture tool developed by Nir Sofer and available from his NorSoft site, today on a Microsoft Windows system. While it was open I visited this website using the Firefox browser on the system and happened to switch back to the HTTPNetworkSniffer window where I noticed an unexpected connection to gn.symcd.com.

HTTPNetwork Sniffer - gn.symcd.com

[More Info ]

[/network/ocsp] permanent link

Sat, Aug 12, 2017 11:03 pm

Using SFC to troubleshoot missing or corrupted system files on Windows Vista

The System File Checker (SFC) tool (sfc.exe) will check the operating system for missing or corrupted files. To use the tool on a Windows Vista system, take the following steps:
  1. Obtain a command prompt by clicking on the Windows logo button normally at the lower left-hand corner of the screen, then select Programs, Accessories, right-click on Command Prompt and choose "Run as administrator". When prompted for permission to continue, click on the Continue button.
  2. At the command prompt, type the command sfc /scannow and hit Enter.

At the conclusion of the scanning process, you will be informed whether any problems were detected.

C:\Windows\system32>sfc/scannow

Beginning system scan.  This process will take some time.

Beginning verification phase of system scan.
Verification 100% complete.

Windows Resource Protection did not find any integrity violations.

C:\Windows\system32>

If there were problems that could not be repaired, you can find information on them by checking the log file produced by the System File Checker tool. The log file is %windir%\Logs\CBS\CBS.log. On most systems, %windir% will be C:\Windows. Typing echo %windir% at a command prompt will show you the directory for the variable. You can open the file in Notepad by typing the command notepad %windir%\Logs\CBS\CBS.log at the command prompt you got by following the steps above.

Or you can use the following steps To determine which files could not be repaired by the System File Checker tool:

  1. Obtain a command prompt with administrator privileges as above by right-clicking on Command Prompt, which is found under Programs then Accessories, and choosing "Run as administrator."
  2. Then type the command findstr /c:"[SR]" %windir%\Logs\CBS\CBS.log >%userprofile%\Desktop\sfcdetails.txt and hit Enter. That will extract relevant entries from the CBS.log file and place them in the file sfcdetails.txt on the Desktop of the user account you are using when you run the command.

    Microsoft Windows [Version 6.0.6002]
    Copyright (c) 2006 Microsoft Corporation.  All rights reserved.
    
    C:\Windows\system32>
    
    Microsoft Windows [Version 6.0.6002]
    Copyright (c) 2006 Microsoft Corporation.  All rights reserved.
    
    C:\Windows\system32>findstr /c:"[SR]" %windir%\Logs\CBS\CBS.log >%userprofile%\D
    esktop\sfcdetails.txt

Note The Sfcdetails.txt file contains details from every time that the System File Checker tool has been run on the computer. The file includes information about files that were not repaired by the System File Checker tool. Verify the date and time entries to determine the problem files that were found the last time that you ran the System File Checker tool. You can find the file on the Windows desktop or click on the Windows Start button, select Search, then For Files or Folders, then type sfcdetails.txt in the search field to search for the file.

References:

  1. How to use the System File Checker tool to troubleshoot missing or corrupted system files on Windows Vista or on Windows 7
    Microsoft Support

[/os/windows/vista] permanent link

Once You Know, You Newegg AliExpress by Alibaba.com

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo