
Python for Secret Agents - Volume II
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Key Features
Discover the essential features of Python programming: statements, variables, expressions, and many of the built-in data types
Use Python's standard library to do more sophisticated data gathering and analysis
Written by a Python programming expert, with over 35 years' experience as a consultant, teacher, author and software developer
Book DescriptionPython is easy to learn and extensible programming language that allows any manner of secret agent to work with a variety of data. Agents from beginners to seasoned veterans will benefit from Python's simplicity and sophistication. The standard library provides numerous packages that move beyond simple beginner missions. The Python ecosystem of related packages and libraries supports deep information processing. This book will guide you through the process of upgrading your Python-based toolset for intelligence gathering, analysis, and communication. You'll explore the ways Python is used to analyze web logs to discover the trails of activities that can be found in web and database servers. We'll also look at how we can use Python to discover details of the social network by looking at the data available from social networking websites. Finally, you'll see how to extract history from PDF files, which opens up new sources of data, and you'll learn about the ways you can gather data using an Arduino-based sensor device. What you will learn
Upgrade Python to the latest version and discover its latest and greatest tools
Use Python libraries to extract data from log files that are designed more for people to read than for automated analysis
Summarize log files and extract meaningful information
Gather data from social networking sites and leverage your experience of analyzing log files to summarize the data you find
Extract text and images from social networking sites
Parse the complex and confusing data structures in a PDF file to extract meaningful text that we can analyze
Connect small, intelligent devices to our computer to use them as remote sensors
Use Python to analyze measurements from sensors to calibrate them and use sensors efficiently
Who this book is forThis book is for Secret Agents who have some exposure to Python. Our focus is on the Field Agents who are ready to do more sophisticated and complex programming in Python. We'll stick to simple statistics for the most part. A steady hand with a soldering iron is not required, but a skilled field agent should be able to assemble a working Arduino circuit to gather their own sensor data.
All prices
More details
Other editions
Additional editions

Person
Steven Lott has been programming since computers were large, expensive, and rare. Working for decades in high tech has given him exposure to a lot of ideas and techniques, some bad, but most are helpful to others. Since the 1990s, Steven has been engaged with Python, crafting an array of indispensable tools and applications. His profound expertise has led him to contribute significantly to Packt Publishing, penning notable titles like "Mastering Object-Oriented," "The Modern Python Cookbook," and "Functional Python Programming." A self-proclaimed technomad, Steven's unconventional lifestyle sees him residing on a boat, often anchored along the vibrant east coast of the US. He tries to live by the words "Don't come home until you have a story."
Content
New Missions, New Tools
Tracks, Trails, and Logs
Following the Social Network
Dredging Up History`
Data Collection Gadgets
Chapter 1. New Missions - New Tools
The espionage job is to gather and analyze data. This requires us to use computers and software tools.
However, a secret agent's job is not limited to collecting data. It involves processing, filtering, and summarizing data, and also involves confirming the data and assuring that it contains meaningful and actionable information.
Any aspiring agent would do well to study the history of the World War II English secret agent, code-named Garbo. This is an inspiring and informative story of how secret agents operated in war time.
We're going to look at a variety of complex missions, all of which will involve Python 3 to collect, analyze, summarize, and present data. Due to our previous successes, we've been asked to expand our role in a number of ways.
HQ's briefings are going to help agents make some technology upgrades. We're going to locate and download new tools for new missions that we're going to be tackling. While we're always told that a good agent doesn't speculate, the most likely reason for new tools is a new kind of mission and dealing with new kinds of data or new sources. The details will be provided in the official briefings.
Field agents are going to be encouraged to branch out into new modes of data acquisition. Internet of Things leads to a number of interesting sources of data. HQ has identified some sources that will push the field agents in new directions. We'll be asked to push the edge of the envelope.
We'll look at the following topics:
- Tool upgrades, in general. Then, we'll upgrade Python to the latest stable version. We'll also upgrade the pip utility so that we can download more tools.
- Reviewing the Python language. This will only be a quick summary.
- Our first real mission will be an upgrade to the Beautiful Soup package. This will help us in gathering information from HTML pages.
- After upgrading Beautiful Soup, we'll use this package to gather live data from a web site.
- We'll do a sequence of installations in order to prepare our toolkit for later missions.
- In order to build our own gadgets, we'll have to install the Arduino IDE.
This will give us the tools for a number of data gathering and analytical missions.
Background briefing on tools
The organization responsible for tools and technology is affectionately known as The Puzzle Palace. They have provided some suggestions on what we'll need for the missions that we've been assigned. We'll start with an overview of the state of art in Python tools that are handed down from one of the puzzle solvers.
Some agents have already upgraded to Python 3.4. However, not all agents have done this. It's imperative that we use the latest and greatest tools.
There are four good reasons for this, as follows:
- Features: Python 3.4 adds a number of additional library features that we can use. The list of features is available at https://docs.python.org/3/whatsnew/3.4.html.
- Performance: Each new version is generally a bit faster than the previous version of Python.
- Security: While Python doesn't have any large security holes, there are new security changes in Python.
- Housecleaning: There are a number of rarely used features that were and have been removed.
Some agents may want to start looking at Python 3.5. This release is anticipated to include some optional features to provide data type hints. We'll look at this in a few specific cases as we go forward with the mission briefings. The type-analysis features can lead to improvements in the quality of the Python programming that an agent creates. The puzzle palace report is based on intelligence gathered at PyCon 2015 in Montreal, Canada. Agents are advised to follow the Python Enhancement Proposals (PEP) closely. Refer to https://www.python.org/dev/peps/.
We'll focus on Python 3.4. For any agent who hasn't upgraded to Python 3.4.3, we'll look at the best way to approach this.
If you're comfortable with working on your own, you can try to move further and download and install Python 3.5. Here, the warning is that it's very new and it may not be quite as robust as the Python version 3.4. Refer to PEP 478 (https://www.python.org/dev/peps/pep-0478/) for more information about this release.
Doing a Python upgrade
It's important to consider each major release of Python as an add-on and not a replacement. Any release of Python 2 should be left in place. Most field agents will have several side-by-side versions of Python on their computers. The following are the two common scenarios:
- The OS uses Python 2. Mac OS X and Linux computers require Python 2; this is the default version of Python that's found when we enter
pythonat the command prompt. We have to leave this in place. - We might also have an older Python 3, which we used for the previous missions. We don't want to remove this until we're sure that we've got everything in place in order to work with Python 3.4.
We have to distinguish between the major, minor, and micro versions of Python. Python 3.4.3 and 3.4.2 have the same minor version (3.4). We can replace the micro version 3.4.2 with 3.4.3 without a second thought; they're always compatible with each other. However, we don't treat the minor versions quite so casually. We often want to leave 3.3 in place.
Generally, we do a field upgrade as shown in the following:
- Download the installer that is appropriate for the OS and Python version. Start at this URL: https://www.python.org/downloads/. The web server can usually identify your computer's OS and suggest the appropriate download with a big, friendly, yellow button. Mac OS X agents will notice that we now get a
.pkg(package) file instead of a.dmg(disk image) containing.pkg. This is a nice simplification. - When installing a new minor version, make sure to install in a new directory: keep 3.3 separate from 3.4. When installing a new micro version, replace any existing installation; replace 3.4.2 with 3.4.3.
- For Mac OS X and Linux, the installers will generally use names that include
python3.4so that the minor versions are kept separate and the micro versions replace each other. - For Windows, we have to make sure we use a distinct directory name based on the minor version number. For example, we want to install all new 3.4.x micro versions in
C:\Python34. If we want to experiment with the Python 3.5 minor version, it would go inC:\Python35.
- For Mac OS X and Linux, the installers will generally use names that include
- Tweak the
PATHenvironment setting to choose the default Python.- This information is generally in our
~/.bash_profilefile. In many cases, the Python installer will update this file in order to assure that the newest Python is at the beginning of the string of directories that are listed in thePATHsetting. This file is generally used when we log in for the first time. We can either log out and log back in again, or restart the terminal tool, or we can use thesource ~/.bash_profilecommand to force the shell to refresh its environment. - For Windows, we must update the advanced system settings to tweak the value of the
PATHenvironment variable. In some cases, this value has a huge list of paths; we'll need to copy the string and paste it in a text editor to make the change. We can then copy it from the text editor and paste it back in the environment variable setting.
- This information is generally in our
- After upgrading Python, use pip3.4 (or easy_install-3.4) to add the additional packages that we need. We'll look at some specific packages in mission briefings. We'll start by adding any packages that we use frequently.
At this point, we should be able to confirm that our basic toolset works. Linux and Mac OS agents can use the following command:
MacBookPro-SLott:Code slott$ python3.4This should confirm that we've downloaded and installed Python and made it a part of our OS settings. The greeting will show which micro version of Python 3.4 have we installed.
For Windows, the command's name is usually just python. It would look similar to the following:
The Mac OS X interaction should include the version; it will look similar to the following code:
MacBookPro-SLott:NavTools-1.2 slott$ python3.4 Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.version_info sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)We've entered the python3.4 command. This shows us that things are working very nicely. We have Python 3.4.3 successfully installed.
We don't want to make a habit of using the python or python3 commands in order to run Python from the command line. These names are too generic and we...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.
File format: PDF
Copy-Protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (only limited: Kindle).
The file format PDF always displays a book page identically on any hardware. This makes PDF suitable for complex layouts such as those used in textbooks and reference books (images, tables, columns, footnotes). Unfortunately, on the small screens of e-readers or smartphones, PDFs are rather annoying, requiring too much scrolling.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our eBook Help page.