⌘ python scripts

reeeeee

Page last updated: Apr 18 2019
#! /usr/bin/env python3
# Justin Scofield
# CIS 299 300
# Program 8

super_powers = ["mind-reading", "lightning", "indestructibility", "super-strength", "radioactivity",
                "perfect memory", "electricity", "fire", "water", "transforming", "stop time", "telekinesis",
                "total recall",
                "magnetism", "flying", "perfect health", "parseltongue", "force fields", "grant wish", "eternal youth",
                "elasticity", "telepathy", "ice", "speed", "invisibility", "weather control", "befriend",
                "disarm enemy"]

def main():
    trySort_powers = []
    readPowerToFile()
    readPowerFromFile(trySort_powers)

def readPowerToFile():  # done
    noSortPower = 'noSortPower.txt'
    with open(noSortPower, 'w') as nsp:
        for power in super_powers:
            nsp.write("%s\n" % power)

def readPowerFromFile(trySort_powers):  # need to remove \n
    # with open("readFromThisFile.txt", "r") as read_stream:
    # for line in read_stream: print(line)
    ### ================================================== ###
    with open('noSortPower.txt', 'r') as pff:
        for each in pff:
            trySort_powers.append(each)
    ### ================================================== ###
    readPowerFromList(trySort_powers)
    print("===============================================")
    sortPowerList(trySort_powers)
    print("===============================================")
    saveSortedPowersList(trySort_powers)

def readPowerFromList(trySort_powers):  # done
    for each in trySort_powers:
        print(each.strip("\n"))

def sortPowerList(trySort_powers):
    for each in sorted(trySort_powers):
        print(each.strip("\n"))

def saveSortedPowersList(trySort_powers):
    sortedPowers = 'sortedPowers.txt'
    with open(sortedPowers, "w") as spl:
        for each in sorted(trySort_powers):
            spl.write(each)

main()

Rock Paper Scissors (Updated)


#! /usr/bin/env python3
# Justin Scofield
# CIS 299 300
# Program 6

import random
rock = 1
paper = 2
scissors = 3

def main():
    print("Welcome to Rock Paper Scissors")
    getPlayerInput()

def getPlayerInput():
    player_input = 1
    while player_input != 0:
        print("\nChoose 1 for rock, 2 for paper, and 3 for scissors.")
        player_input = int(input("Your choice: "))
        # included the & statement to avoid 0 creating issues with printResult
        if player_input <= 3 & player_input != 0:
            printResult(player_input)
        elif player_input == 0:
            print("Thank you for playing!")
            exit()
        else:
            print("That is not an option. Please input a valid response.")

def getCompInput():
    random_input = random.randrange(1, 4, 1)
    return random_input

def printResult(player_input):
    if player_input == 1:
        player_choice = "Rock"
    elif player_input == 2:
        player_choice = "Paper"
    elif player_input == 3:
        player_choice = "Scissors"

    comp_input = getCompInput()
    if comp_input == 1:
        comp_choice = "Rock"
    elif comp_input == 2:
        comp_choice = "Paper"
    elif comp_input == 3:
        comp_choice = "Scissors"

    print("You chose %s" % player_choice)
    print("The computer chooses %s" % comp_choice)
    determineWinner(player_input, comp_input)

def determineWinner(player_input, random_input):
    if player_input == random_input:
        print("The game is a tie.")

    elif player_input == paper:
        if random_input == rock:
            print("Paper covers rock, you win!")
        elif random_input == scissors:
            print("Scissors cuts paper, you lose!")

    elif player_input == scissors:
        if random_input == rock:
            print("Rock crushes scissors, you lose!")
        elif random_input == paper:
            print("Scissors cuts paper, you win!")

    elif player_input == rock:
        if random_input == scissors:
            print("Rock crushes scissors, you win!")
        elif random_input == paper:
            print("Paper covers rock, you lose!")

main()

Inventory Data Report


#! /usr/bin/env python3
# Justin Scofield
# CIS 299 300
# Program 5

A1 = "Adapter", "Bluetooth",  284,  23.64
A2 = "Adapter", "Cisco",  203,  228.76
A3 = "Adapter", "Desktop",  70,  54.17
A4 = "Adapter", "External",  813,  6.62
A5 = "Adapter", "vHP",  50,  28.99
A6 = "Adapter", "Intel", 44, 88.57
A7 = "Adapter", "Netgear", 505, 622.64
A8 = "Adapter", "Over 1Gps", 86, 154.99
A9 = "Adapter", "PCI-E", 1003, 159.99
A10 = "Adapter", "Rackmount", 27, 266.00
A11 = "Adapter", "Rail-mountable", 40, 5.31
A12 = "Adapter", "Range Extender", 22, 9.18
A13 = "Adapter", "Stackable", 45, 9.46
A14 = "Adapter", "Up to 1Gps", 182, 30.95
A15 = "Adapter", "Wall Mountable", 455, 24.93
A16 = "Adapter", "Wired", 45, 76.17
A17 = "Adapter", "Wireless", 63, 196.73
A18 = "Adapter", "vZyXel", 63, 10.67
F1 = "Firewall", "vCisco", 351, 102.99
F2 = "Firewall", "Wired", 86, 154.99
F3 = "Firewall", "Wireless", 853, 159.99
F4 = "Firewall", "ZyXel",  27, 266.00
F5 = "Firewall", "PCI-E",  22, 159.99
F6 = "Firewall", "Rackmount", 45, 5.31
F7 = "Firewall", "Rail-mountable",  45, 9.18
F8 = "Firewall", "Range Extender", 63, 9.46
F9 = "Firewall", "Stackable", 182, 30.99
F10 = "Firewall", "Up to 1Gps", 316, 266.00
NAS1 = "Network Attached Storage", "Desktop", 40, 5.31
NAS2 = "Network Attached Storage", "External", 22, 9.18
NAS3 = "Network Attached Storage", "Rackmount", 45, 9.46
NAS4 = "Network Attached Storage", "Rail-mountable", 182, 30.95
NAS5 = "Network Attached Storage", "Stackable", 455, 24.93
NAS6 = "Network Attached Storage", "Wall Mountable", 45, 76.17
NAS7 = "Network Attached Storage", "Wired", 63, 196.73
NAS8 = "Network Attached Storage", "Wireless", 731, 535.47
NIC1 = "Network Interface Card", "Cisco", 316, 6.18
NIC2 = "Network Interface Card", "HP", 903, 11.00
NIC3 = "Network Interface Card", "Intel", 24, 35.99
NIC4 = "Network Interface Card", "Over 1Gps", 78, 10.67
NIC5 = "Network Interface Card", "PCI-E", 561, 7.70
NIC6 = "Network Interface Card", "Up to 1Gps", 56, 27.49
R1 = "Router", "Cisco", 55, 724.00
R2 = "Router", "Desktop", 62, 55.99
R3 = "Router", "External", 250, 129.99
R4 = "Router", "Netgear", 225, 62.99
R5 = "Router", "Rackmount", 624, 35.99
R6 = "Router", "Rail-mountable", 49, 394.00
R7 = "Router", "Range Extender", 62, 55.99
R8 = "Router", "Stackable", 390, 17.99
R9 = "Router", "Wall Mountable", 96, 29.99
R10 = "Router", "Wired", 250, 129.99
R11 = "Router", "Wireless", 624, 35.99
R12 = "Router", "ZyXel", 49, 394.00
SW1 = "Switch", "Cisco", 78, 62.99
SW2 = "Switch", "Desktop", 390, 17.99
SW3 = "Switch", "External", 96, 29.99
SW4 = "Switch", "HP", 250, 29.99
SW5 = "Switch", "Intel", 390, 69.99
SW6 = "Switch", "Netgear", 561, 55.99
SW7 = "Switch", "Rackmount", 1115, 69.99
SW8 = "Switch", "Rail-mountable", 30, 199.99
SW9 = "Switch", "Range Extender", 56, 129.99
SW10 = "Switch", "Stackable", 62, 899.99
SW11 = "Switch", "Wall Mountable", 55, 57.99
SW12 = "Switch", "Wired", 55, 35.99
SW13 = "Switch", "Wireless", 225, 394.00
SW14 = "Switch", "ZyXel", 62, 17.99

all_lists = [list(A1), list(A2), list(A3), list(A4), list(A5), list(A6), list(A7), list(A8), list(A9), list(A10), list(A11), list(A12), list(A13), list(A14), list(A15), list(A16), list(A17), list(A18), list(F1), list(F2), list(F3), list(F4), list(F5), list(F6), list(F7), list(F8), list(F9), list(F10), list(NAS1), list(NAS2), list(NAS3), list(NAS4), list(NAS5), list(NAS6), list(NAS7), list(NAS8), list(NIC1), list(NIC2), list(NIC3), list(NIC4), list(NIC5), list(NIC6), list(R1), list(R2), list(R3), list(R4), list(R5), list(R6), list(R7), list(R8), list(R9), list(R10), list(R11), list(R12), list(SW1), list(SW2), list(SW3), list(SW4), list(SW5), list(SW6), list(SW7), list(SW8), list(SW9), list(SW10), list(SW11), list(SW12), list(SW13), list(SW14)]

def main():
    print("Welcome to the Inventory Manager App\n")
    x = " "
    while x != "0":
        print("\n1) Run Adapter Report")
        print("2) Run Firewall Report")
        print("3) Run Network Attached Storage Report")
        print("4) Run Network Interface Card Report")
        print("5) Run Router Report")
        print("6) Run Switch Report")
        print("7) Run All Inventory Report")
        print("---------------------------")
        print("0) Exit Program")
        x = input("Please make a choice 1-7 or Quit: ")
        if x == "1":
            run_report("Adapter")
        elif x == "2":
            run_report("Firewall")
        elif x == "3":
            run_report("Network Attached Storage")
        elif x == "4":
            run_report("Network Interface Card")
        elif x == "5":
            run_report("Router")
        elif x == "6":
            run_report("Switch")
        elif x == "7":
            run_all_reports()
        else:
            print("Invalid Input. Try again.")

def run_report(category):
    print("Inventory Report: %s" % category)
    print("=========================================")
    print("Item Name \t\t Inventory \t\t Value")
    invCounter = 0
    invValue = 0
    for each in all_lists:
        if each[0] == category:
            print('{0:>20}{1:>20}{2:>20}'.format(each[1],each[2],each[3]))
            invCounter = invCounter + each[2]
            invValue = invValue + (each[2] * each[3])
    print("\nItem in Inventory Summary:")
    print("=========================================")
    print("Average Value: ${:,.2f}".format(invValue/invCounter))
    print("Total Items in Inventory = {:,}".format(invCounter))
    print("Total Value Inventory: ${:,.2f}".format(invValue))

main()

Car Inventory Data

#! /usr/bin/env python3
# Justin Scofield
# CIS 299 300
# Program 4

# inventoryList =  [Model, MSRP, Cars in Inventory]

car1 = ["Chevy Bolt EV",37495,2]
car2 = ["Kia Niro",24485,23]
car3 = ["VW e-Golf",32790,12]
car4 = ["Hyundai Kona",37495,3]
car5 = ["Honda Insight",23725,4]
car6 = ["Chevrolet Volt",34395,14]
car7 = ["Hyundai Ioniq",23285,5]
car8 = ["Tesla Model 3",45200,1]
car9 = ["Audi e-tron",75795,2]
car10 = ["Toyota Prius",24405,12]
inventoryList = [car1,car2,car3,car4,car5,car6,car7,car8,car9,car10]

def printCarList(): #iterates over every list in the inventory for amount and model
    print("------------------------------------")
    print("Vehicle Inventory by Type")
    print("Inventory \t\tMake/Model \t\t")
    for each in inventoryList:
        print("\t%d\t\t%s \t\t" % (each[2], each[0]))

def countInventory(): # adds up the inventory amount of each
    print("------------------------------------")
    print("Total Vehicle Stock Count")
    # x being the vehicle amount pulled from inventory list
    product = sum(x[2] for x in inventoryList[0:])
    print("There are %d cars in inventory" % product)

def printInventoryValue(): # takes the sum of the cars value and how many there are and multiplies
    print("------------------------------------")
    print("Total Vehicle Stock Value\n")
    stockprice = sum(z[1] for z in inventoryList[0:])
    stockamt = sum(y[2] for y in inventoryList[0:])
    stockval = stockprice * stockamt
    print("$"+"{:,.2f}".format(stockval)) # formatted for currency commas and change

def printEachCarValue(): # displays price of each car based on how many in stock
    print("------------------------------------")
    print("Vehicle Stock Value by Model\n")
    for every in inventoryList:
        print("%s inventory value = ${:,.2f}".format(every[2]*every[1]) % every[0])

def getHighest(): # takes the highest priced car and displays
    print("------------------------------------")
    print("The vehicle with the highest MSRP:")
    highest = max(inventoryList[0:], key=lambda w: w[1])
    print("%s with an MSRP of ${:,.2f}".format(highest[1]) % highest[0])

def getLowest(): # lowest car
    print("------------------------------------")
    print("The vehicle with the lowest MSRP:")
    lowest = min(inventoryList[0:], key=lambda v: v[1])
    print("%s with an MSRP of ${:,.2f}".format(lowest[1]) % lowest[0])

def mainLoop():
        print("Welcome to Eletric Avenue")
        x = "24"
        while x != "0":
            print("\nEnter 1) View All Cars in Inventory")
            print("Enter 2) Get Total Car Count")
            print("Enter 3) Get Total Inventory Value")
            print("Enter 4) Get Inventory Value by Car")
            print("Enter 5) Get Highest Priced Car")
            print("Enter 6) Get Lowest Priced Car")
            print("\nEnter 0 to end")
            x = input("Please make a selection:")
            if x == "1":
                printCarList()
            elif x == "2":
                countInventory()
            elif x == "3":
                printInventoryValue()
            elif x == "4":
                printEachCarValue()
            elif x == "5":
                getHighest()
            elif x == "6":
                getLowest()
            else:
                print("Thank you for using the inventory system.")

mainLoop()

Zeniea Twitter bot

I've decided while I'm taking my Intro to Python course that I'll work on using the Twitter API with Python to control the @zeniea_ account that I used to use to post zQuest updates. I'm working on what I want to do with the bot right now, the code below is only the beginning of the file. I'm looking into the tkinter library just to interface with for the moment. I'll add more to this. However, if you wanted to connect to your Twitter Developer Account, this will print your username. Lol.

#! /usr/bin/env python3
# Justin Scofield
# Feb 3 2019
# Zeniea Twitter Bot

# Adding tweepy for Twitter, Tkinter for personal GUI
import tweepy
from tkinter import *

# Twitter Application Consumer API Key and Access Token
consumer_key = 'express123'
consumer_secret = 'express12345'
access_token = 'AkitronSucks'
access_token_secret = 'AkitronSucksALot'

# Authenticate Twitter account
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

user = api.me()
print ("Welcome to the bot prompt, %s" % (user.name))
print ()

Inventory Loop Subroutine

#! /usr/bin/env python3
# Justin Scofield
# CIS 299 300
# Program 3

print("Welcome User")
print("\nThis program allows a user to enter items")
print("related to the inventory of a hardware store.")
print("Users will enter: Item Name, Item Quantity and Item Cost.")
print("At the end a summary report is displayed.")
print("New Item: ")

no = ["n", "no", "N", "NO"]
totalQuantity = []
totalCost = []

def inventoryAdd():
    itemName = input("Please enter the item name: ")
    itemQuantity = int(input("Please enter the item quantity: "))
    itemCost = float(input("Please enter the item cost: "))
    totalQuantity.append(itemQuantity)
    totalCost.append(itemCost * itemQuantity)
    inventoryValue = itemQuantity * itemCost
    print("  Summary for this item: ")
    print("    Item Name:       %s" % itemName)
    print("    Total Quantity:  %s" % itemQuantity)
    print("    Item Cost:       $%0.2f" % itemCost)
    print("    Inventory Value: $%0.2f" % inventoryValue)

def finish():
    print("\nThank you\nCalculating totals...")
    print("\nHardware Store Inventory Report")
    print("-------------------------------")
    print("Total Items in Inventory: %g" % sum(totalQuantity))
    print("Total Value of Inventory: $%0.2f" % sum(totalCost))
    return

while True:
    inventoryAdd()
    entry = input("To enter another item press 'y', else press 'n': ")
    if entry in no:
        finish()
        break
    else:
        continue

USD to YEN Conversion

I'm really only putting this here as a formality considering how mundane this script is but I want to have record of the bottom of my abilities lol.

# JUSTIN SCOFIELD
# CIS 299 300
# ASSIGNMENT PROGRAM 1 USD TO YEN CONVERSION

# VARIABLES USED
# USD - THE PROMPTED INPUT FOR THE AMOUNT IN DOLLARS TO BE CONVERTED
# YEN - THE CONVERSION RATE MULTIPLIED BY THE INPUTED DOLLAR AMOUNT

print("Hello, user.") #greet user
print("This program will convert US dollars into yen.") #define the task
print() #print a blank line for aesthetic
usd = float(input('Amount of dollars: '))
#float the input in case of decimal points
yen = usd * 114.62
#multiply the inputted value by the conversion rate
print("Processing...")
print(usd, "U.S. dollars equals", yen , "yen")
#repeat the input, then display the output with text