Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

I have a Python script that checks a mailbox, parses some stuff out, makes a new email and sends that to another system. The mailbox keeps all the mail it receives, so people can go back and look at it later or whatever reason. Right now it's a manual process where someone cuts/pastes poo poo into an application, from the email messages. I'm using poplib to get the messages.

My question is what would the 'best' way to keep track of what emails has the script already 'seen'?

Should I get an md5 of the message and store it? It seems inefficient to download each message and check it, but all it seems you can get is [message_num, octets] when you get the list of available messages. Is there a unique id of sorts in the email header that I could rely on instead?

Should I stick these all in sqlite or MySQL databases or is that overkill? I'm thinking if I did that I could store the resulting outgoing email along with the date/time it was sent to the other system as well, and that might be useful for logging.

Should I just write some kind of id of each message to a text file and check the end of the file to see what the last message was?

Adbot
ADBOT LOVES YOU

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

I'm trying to figure out what the least-dumb way to assign a service tech based on a map of highlighted states. Each rep has 1 or more states that they are responsible for, and i want to email the responsible tech when a ticket comes in from a store in their state. I'm new to Python.

code:
    states = ['TX', 'OK']
    if d.get('State Abbreviation') in states:
      responsibleTech = 'jim'

    states = ['AR', 'LA', 'MS', 'AL', 'GA', 'TN']
    if d.get('State Abbreviation') in states:
      responsibleTech = 'mark'

    states = ['FL']
    if d.get('State Abbreviation') in states:
      responsibleTech = 'dave'

    states = ['MI', 'IL', 'IN', 'OH', 'NC', 'SC']
    if d.get('State Abbreviation') in states:
      responsibleTech = 'tom'

    states = ['KY', 'WV', 'VA', 'MD', 'DE', 'NJ', 'CT', 'RI', 'MA', 'ME', 'NH', 'VT',
        'NY', 'PA']
    if d.get('State Abbreviation') in states:
      responsibleTech = 'bill'

    states = ['WA', 'OR', 'ID', 'MT', 'WY', 'UT', 'CO', 'NM', 'ND', 'SD', 'NE', 'KS',
        'MN', 'IA', 'MO', 'WI']
    if d.get('State Abbreviation') in states:
      responsibleTech = 'joe'
Would some kind of 2D array work better? Trying to not repeat myself as much as I can as well as make it easy to change techs/states later down the road.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Jose Cuervo posted:

You could create a dictionary with each state mapped to the tech responsible:
Python code:
state_to_tech = {'TX': 'jim,
        'OK': 'jim',
        'AR': 'mark', 
....}
and then use the following line
Python code:
responsible_tech = state_to_tech[d.get('State Abbreviation')]
This only works if each state is taken care of by a single tech.

We use 1 tech per state right now.

I thought about that, but then if we fire a tech and hire a new one I have to change the tech assigned to like, 15 states in some cases.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

What's the preferred way to interface with DB2 databases? PyDB2 looks pretty out of date.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Under Windows what's the most straightforward library to print something like a label from python?

Using whatever font and size (Courier 20), and then whatever paper size (4x6) for example.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Bob Morales posted:

Under Windows what's the most straightforward library to print something like a label from python?

Using whatever font and size (Courier 20), and then whatever paper size (4x6) for example.

Here's what I ended up doing:

code:
import win32api
import win32print
from fpdf import FPDF

label = FPDF(orientation='P', unit='pt', format=(144,25.2)) # 2" x 0.35"
label.set_margins(0,0) # we don't want margins
label.set_auto_page_break(0) # turn of page breaks so we don't waste labels

# [part number, quantity]
parts_list = [['12345678', 6], ['ABCDEFGH', 10], ['SOME-PART', 4], ['FOOBAR', 20], ['FUNBUN', 2]]

for p in parts_list:
	for i in range(0, p[1]): # print a label for each individual part
		label.add_page()
		label.set_font('Courier', 'B', 18)
		label.cell(144, 25, p[0], 0, 0, 'C')

label.output('TEMP_LABEL.pdf')

win32api.ShellExecute (0, "printto", 'TEMP_LABEL.PDF', '\\\\ps1\\FUCKING_PRINTER', ".", 0)
Results:

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Quick Flask question, trying to write a simple chat server and was going to just store messages in a list structure

code:
from flask import Flask
app = Flask(__name__)

count = 0

@app.route('/')
def index():
        count = count + 1
        return '<h2>Server is running and has served %s requests</h2>' % count

if __name__ == '__main__':
        app.run(debug=True)                                   
But of course I get the error UnboundLocalError: local variable 'count' referenced before assignment

I'm sure I'll eventually move this over to some kind of fancier datastore but this is just for testing. How can I access the same variable across functions in a Flask program?

Adbot
ADBOT LOVES YOU

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Dominoes posted:

Hey dudes. What are the best ways to learn Python, for someone with no experience? I learned from Codeacademy, which was OK. The OP looks out of date.

If you have access to O'Reilly books, I would start with 'Learning Python' and then 'Python Cookbook'. You learn 'this is Python' and then they show you 'this is how to do stuff with it'

  • Locked thread