def usps_validate(address):
    text = address.split(',')
    usps_address = Address(name='',
                           address_1=text[0],
                           city=text[1],
                           state=text[2],
                           zipcode='')
    usps = USPSApi('686NONE02749', test=True)
    validation = usps.validate_address(usps_address)
    print(validation.result)
Example #2
0
async def track(ctx, package: str):
    api = os.getenv("USPS_API")
    usps = USPSApi(api)
    response = usps.track(package)
    description = response.result['TrackResponse']['TrackInfo']
    if "Error" in description:
        msg = """```css
- {}
```""".format(description["Error"]["Description"])
        print(msg)
        await ctx.send(msg)
    else:
        await ctx.send("hold, i havent implemented working tracking number")
Example #3
0
def search():
    form = ZipCodeSearch(request.form)
    if request.method == 'POST' and form.validate():
        address = Address(name=form.name.data,
                          address_1=form.address_1.data,
                          address_2=form.address_2.data,
                          city=form.city.data,
                          state=form.state.data,
                          zipcode=form.zipcode.data)
        usps = USPSApi('646STUDE1062', test=True)
        validation = usps.validate_address(address)
        # flash('Address is %s, %s, %s, %s, %s, %s', 'success')
        flash(validation.result, 'success')
        return redirect(url_for('newaddress'))
    return render_template('search.html', form=form)
Example #4
0
    def post(self, *args, **kwargs):
        form = CheckoutForm(self.request.POST or None)
        if form.is_valid():
            name = form.cleaned_data.get("name")
            street_address = form.cleaned_data.get("street_address")
            country = form.cleaned_data.get("country")
            state = form.cleaned_data.get("state")
            city = form.cleaned_data.get("city")
            zip = form.cleaned_data.get("zip")

            address = Address(
                name=name,
                address_1=street_address,
                city=city,
                state=state,
                zipcode=zip,
            )

            usps = USPSApi("097UNIVE5841", test=True)
            validation = usps.validate_address(address)
            try:
                valid = validation.result["AddressValidateResponse"][
                    "Address"]["Address1"]
                billing_address = BillingAddress(
                    user=self.request.user,
                    street_address=street_address,
                    country=country,
                    state=state,
                    city=city,
                    zip=zip,
                )
                existing_address = BillingAddress.objects.filter(
                    user=self.request.user).count()
                if existing_address != 0:
                    BillingAddress.objects.filter(
                        user=self.request.user).delete()
                    billing_address.save()
                    return redirect("core:order-confirmation")
                else:
                    billing_address.save()
                    return redirect("core:order-confirmation")
            except:
                messages.warning(self.request, "Not a Valid Address")

            return redirect("core:checkout")
        messages.warning(self.request, "Failed Checkout")
        return redirect("core:checkout")
# https://pypi.org/project/usps-api/
from usps import USPSApi, Address

address = Address(name='Tobin Brown',
                  address_1='1234 Test Ave.',
                  city='Test',
                  state='NE',
                  zipcode='55555')
usps = USPSApi('XXXXXXXXXXXX', test=True)
validation = usps.validate_address(address)
print(validation.result)
Example #6
0
from usps import USPSApi

df = pd.DataFrame({
    'Tracking Number': [
        '10X4R3W', '30X5R3W', '9410808205497580311496',
        '9410808205497580311496', '9410808205497580311496'
    ],
    'A': [3, 4, 7, 6, 1],
    'Shipper': ['Fedex', 'Fedex', 'USPS', 'USPS', 'USPS']
})
print(df)

s = 30

#df1 = df[df['Sales'] >= s]
df1 = df[df['Shipper'] == 'Fedex']
df2 = df[df['Shipper'] == 'USPS']

print(df1)
print()
print(df2)
print()

for i in df2['Tracking Number']:
    usps = USPSApi('107GOFAS1661')
    # sample tracking number 9410808205497580311496

    track = usps.track(i)

    print(track.result)
Example #7
0
    else:
        stype = str(streett)
    if pd.isnull(streetd):
        fulladdress = [str(streetnum), str(streetnm), str(stype)]
    else:
        fulladdress = [str(streetnum), str(streetd), str(streetnm), str(stype)]
    x = ' '.join(fulladdress)
    firstline = str(x.replace("  ", " ") + ".")
    citys = str(cityz)
    zipcodes = str(zipcodez)
    address = Address(name='',
                      address_1=units,
                      address_2=firstline,
                      city=citys,
                      state='NV',
                      zipcode=zipcodes)
    usps = USPSApi('XX_YourUserName_XX', test=True)
    validation = usps.validate_address(address)
    valids = str(validation.result)
    print(firstline)
    print(validation.result)
    checkerror = "Error"
    #      Uncomment to report default addresses
    #      defaults = "Default"
    #      if checkerror in valids or defaults in valids:
    if checkerror in valids:
        with open('out.txt', 'a') as f:
            with redirect_stdout(f):
                print(firstline)
                print(validation.result)
redisHost = os.getenv("REDIS_HOST") or "localhost"
rabbitMQHost = os.getenv("RABBITMQ_HOST") or "localhost"
#checking connection and establishing channel for communication
print("Connecting to rabbitmq({}) and redis({})".format(rabbitMQHost,redisHost))
connection=pika.BlockingConnection(pika.ConnectionParameters(host=rabbitMQHost))
channel=connection.channel()

channel.queue_declare(queue='worker_queue', durable=True)

#connect to redis database
trackingNumtoInfo = redis.Redis(host=redisHost, db=1)


# USPS Login and Order class structure
uspsLogin='******'
usps = USPSApi(uspsLogin)

class Order:
	trackingTime = None
	trackingDate = None
	trackingEvent = None

def getTrackingInfo(order, number):
	# Grab data for an order via the tracking number
	# NOTE: A tracking number can only be called 35 times before exhausting the resource
	try:
		trackingInfo = usps.track(number)

		# Grab data for most recent update
		order.trackingTime = trackingInfo.result['TrackResponse']['TrackInfo']['TrackDetail'][0]['EventTime']
		order.trackingDate = trackingInfo.result['TrackResponse']['TrackInfo']['TrackDetail'][0]['EventDate']
Example #9
0
REDDIT_CLIENT_ID = ""
REDDIT_CLIENT_SECRET = ""
REDDIT_USERNAME = ""
REDDIT_PASSWORD = "******"

# Careful as you release this into the wild!
SUB_TO_MONITOR = "test"

REPLY_TEMPLATE = "ZIP Code {zip} is {city}, {state}"
REPLY_INVALID_TEMPLATE = '{zip} is not a valid ZIP code, according to the USPS.'
REPLY_TAG = '\n\n^(Created by u/grtgbln)'

logging.basicConfig(level=logging.INFO,
                    format="%(asctime)s - %(levelname)s - %(message)s")

usps = USPSApi(USPS_USERID)

db = sql.SQL(sql_type='SQLite', sqlite_file='zip_code_entries.db')

reddit = praw.Reddit(client_id=REDDIT_CLIENT_ID,
                     client_secret=REDDIT_CLIENT_SECRET,
                     user_agent='ZipCodeBot (by u/grtgbln)',
                     username=REDDIT_USERNAME,
                     password=REDDIT_PASSWORD)
if not reddit.read_only:
    logging.info("Connected and running.")


def search_zip(zip_code):
    zip = usps.lookup_city_by_zip(str(zip_code), just_answer=True)
    return zip.result
Example #10
0
import xlwt
import sys
import json
import argparse
from xlwt import Workbook
from usps import USPSApi


usps_instance = USPSApi('')  # API Key Here

packages = []


def returnPackage(tracking, desc):
    packageStatus = usps_instance.track(tracking).result.get(
        'TrackResponse').get('TrackInfo').get('TrackSummary')
    return {'tracking': tracking,
            'desc': desc,
            'time': packageStatus.get('EventTime'),
            'date': packageStatus.get('EventDate'),
            'state': packageStatus.get('EventState'),
            'city': packageStatus.get('EventCity'),
            'status': packageStatus.get('Event')
            }


def standardizeInput(string):
    if "-" in string:
        x = string.split("-")
        trackingNum = x[0].strip()
        desc = x[1].strip()
Example #11
0
from usps import USPSApi, Address

address = Address(name='Suhas Nithyanandappa',
                  address_1='60 Vinatge Circle, Apt 307',
                  city='Pleasanton',
                  state='CA',
                  zipcode='94566')

# address = Address(
#     name='Gate 6, 1600 Marietta Rd NW',
#     address_1='SP Richards CO DC, 190 Selig Drive',
#     city='Atlanta',
#     state='GA',
#     zipcode='30336'
# )
usps = USPSApi('321BLUME7569', test=True)
validation = usps.validate_address(address)
print(validation.result)
Example #12
0
from usps import USPSApi
import json
import sys
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import os
usps = USPSApi(os.environ.get('USPS_num'))
#9200190246573223291412 crystals track
#9500126510460081342890 vivians track
#9374869903504598954074 michelle's track
#9449010205561009777268 caleb's track
#print(type(track.result))
#with open('usps.json', 'w') as outfile:
#    json.dump(usps.track("4205693592023999991074543450879419").result, outfile, indent=4)


def get_info(trackingNum):
    tracking_results = usps.track(trackingNum).result
    print(tracking_results)
    if (tracking_results["TrackResponse"]["TrackInfo"]["TrackSummary"]
        ["EventTime"]) == None:
        current_time = ""
    else:
        current_time = tracking_results["TrackResponse"]["TrackInfo"][
            "TrackSummary"]["EventTime"]
    current_date = tracking_results["TrackResponse"]["TrackInfo"][
        "TrackSummary"]["EventDate"]
    current_status = tracking_results["TrackResponse"]["TrackInfo"][