How to change date format using datetime from openpyxl? [duplicate] - python

This question already has answers here:
Parse date string and change format
(10 answers)
How to convert a date string to different format [duplicate]
(2 answers)
Closed 28 days ago.
This post was edited and submitted for review 27 days ago.
I would like to create a function that will convert the date from a string variable to a date format for further processing. The problem is that I managed to isolate the fields where there is no entry "date" : [], but I can't create an if condition that would distinguish the date format string.
my code:
input: json file
{
"entries": [
{
"attributes": {
"cn": "Diana Troy",
"sn": "Troy",
"givenName": "Diana",
"sAMAccountName": "wonder-woman",
"userAccountControl": 514,
"whenCreated": "2015-09-22 10:21:02+00:00",
"whenChanged": "2023-01-11 09:33:59+00:00",
"lastLogonTimestamp": [],
"pwdLastSet": "2023-01-11 09:33:59.608543+00:00",
"accountExpires": "9999-12-31 23:59:59.999999+00:00"
},
"dn": "CN=Diana Troy,OU=Users,OU=DC-COMICS,DC=universum,DC=local"
}
]
}
code:
with open(encoded_retrieved_users, 'r', encoding="UTF-8") as file:
data = json.load(file)
retrieved_users = data['entries']
retrieved_users.sort(key=lambda d: d["attributes"]["sn"]) # sortuje po sAMAccountName
def is_value(var):
if type(var) is int:
val = var
elif type(var) is str:
val = var
else:
val = None
return val
def to_short_date_format(string_to_format):
if is_value(string_to_format) == None:
short_date = "NO DATE"
else:
short_date = string_to_format
return short_date
for user in retrieved_users:
attributes = user['attributes']
userAccountControl = is_value(attributes['userAccountControl'])
whenCreated = to_short_date_format(attributes['whenCreated'])
whenChanged = to_short_date_format(attributes['whenChanged'])
lastLogonTimestamp = to_short_date_format(attributes['lastLogonTimestamp'])
pwdLastSet = to_short_date_format(attributes['pwdLastSet'])
accountExpires = to_short_date_format(attributes['accountExpires'])
print("userAccountControl | " + str(userAccountControl) + " | " + str(type(userAccountControl)))
print("whenCreated | " + whenCreated + " | " + str(type(whenCreated)))
print("whenChanged | " + whenChanged + " | " + str(type(whenChanged)))
print("lastLogonTimestamp | " + str(lastLogonTimestamp) + " | " + str(type(lastLogonTimestamp)))
print("pwdLastSet | " + str(pwdLastSet) + " | " + str(type(pwdLastSet)))
print("accountExpires | " + accountExpires + " | " + str(type(accountExpires)))
print("----------------------------------")
output:
wonder-woman
userAccountControl | 514 | <class 'int'>
whenCreated | 2015-09-22 10:21:02+00:00 | <class 'str'>
whenChanged | 2023-01-11 09:33:59+00:00 | <class 'str'>
lastLogonTimestamp | NO DATE | <class 'str'>
pwdLastSet | 2023-01-11 09:33:59.608543+00:00 | <class 'str'>
accountExpires | 9999-12-31 23:59:59.999999+00:00 | <class 'str'>
----------------------------------
what i would like to get:
def to_short_date_format(string_to_format):
if is_value(string_to_format) == None:
short_date = "NO DATE"
else:
if string_to_format == <string format %Y-%m-%d %H:%M:%S%z>
dt = datetime.strptime(string_to_format, '%Y-%m-%d %H:%M:%S%z')
short_date = dt.strftime('%Y-%m-%d')
elif string_to_format == <string format %Y-%m-%d %H:%M:%S.%f%z>
dt = datetime.strptime(string_to_format, '%Y-%m-%d %H:%M:%S.%f%z')
short_date = dt.strftime('%Y-%m-%d')
return short_date
output:
wonder-woman
userAccountControl | 514
whenCreated | 2015-09-22
whenChanged | 2023-01-11
lastLogonTimestamp | NO DATE
pwdLastSet | 2023-01-11
accountExpires | 9999-12-31
----------------------------------

I was able to get the output by reusing your snippet. Minor catch is that the date format that you were trying to extract was wrong :
my_date = "2013-06-10 11:50:16+00:00"
# print(my_date)
# print(type(my_date))
from datetime import datetime
dt =datetime.strptime(my_date, '%Y-%m-%d %H:%M:%S%z')
print(dt)
dt_new = dt.strftime('%Y-%m-%d')
print(dt_new)
Output:

Related

is there a way to find duplicated value that has both the same address and pickup date in two different table?

I am currently working on a delivery app. Basically, what I am trying to achieve here is to have a counter that display out any potential duplicated jobs that the customer might have accidently double entered.
The criteria to be considered as a duplicated job is as such:
Has to have same delivery_address and same pickup_date.
This is my postgresql tables:
class Order(models.Model):
id_order = models.AutoField(primary_key=True)
class OrderDelivery(models.Model):
order = models.ForeignKey(Order, on_delete=models.SET_NULL, null=True, blank=True)
delivery_address = models.TextField()
class OrderPickup(models.Model):
order = models.ForeignKey(Order, on_delete=models.SET_NULL, null=True, blank=True)
pickup_date = models.DateField(blank=True, null=True)
This is what I have came up with so far:
def dashboard_duplicated_job(orders, month):
# This function finds for jobs that has
# (1) exact pickup_date
# (2) exact delivery address
# and mark it as duplicated job.
# Find current month, if not take current year
now = timezone.localtime(timezone.now())
month = "12" if month and int(month) == 0 else month
if month == 12 or month == '12':
now = timezone.localtime(timezone.now())
last_month = now.today() + relativedelta(months=-1)
start_date = last_month.replace(day=1).strftime('%Y-%m-%d')
year = last_month.replace(day=1).strftime('%Y')
month = last_month.replace(day=1).strftime('%m')
last_day = calendar.monthrange(int(year), int(month))[1]
string_start = str(year) + "-" + str(month) + "-01"
string_end = str(year) + "-" + str(month) + "-" + str(last_day)
start_date = datetime.strptime(string_start + " 00:00:00", "%Y-%m-%d %H:%M:%S")
end_date = datetime.strptime(string_end + " 23:59:59", "%Y-%m-%d %H:%M:%S")
else:
year = now.year
last = calendar.monthrange(year, int(month))[1]
string_start = str(year) + "-" + str(month) + "-01"
string_end = str(year) + "-" + str(month) + "-" + str(last)
start_date = datetime.strptime(string_start + " 00:00:00", "%Y-%m-%d %H:%M:%S")
end_date = datetime.strptime(string_end + " 23:59:59", "%Y-%m-%d %H:%M:%S")
# Filter pickup_date of Orderpickup to display only orders related to current month
opu = OrderPickup.objects.filter(
order_id__in=orders,
pickup_date__range=(start_date, end_date)
).values(
'order_id',
'pickup_date',
)
# Filter OrderDelivery based on pickup_date range
ods = OrderDelivery.objects.filter(
order_id__in=opu.values('order_id')
).values(
'order_id',
'delivery_address',
# 'reference_no'
)
# Find duplicated delivery_address
dup_ods = ods.values(
'delivery_address'
).annotate(
duplicated_delivery_address=Count('delivery_address')
).filter(
duplicated_delivery_address__gt=1
)
# Extract the IDs of the duplicated delivery_address from dup_ods
dup_ods_id = ods.filter(
delivery_address__in=[item['delivery_address'] for item in dup_ods]
).values(
'order_id'
)
# Find duplicated pickup_date based on duplicated_address <not working as intended>
dup_opu = opu.filter(
order_id__in=dup_ods_id
).values(
'pickup_date'
).annotate(
duplicated_pickup_date=Count('pickup_date')
).filter(
duplicated_pickup_date__gt=1
)
dup_opu_id = opu.filter(
pickup_date__in=[item['pickup_date'] for item in dup_opu]
).order_by()
orders = orders.filter(id_order__in=dup_opu_id)
return orders
Based on what I have came up with, I am having situation where orders that has same delivery_address but different pickup_date is showing up.
example (correct):
| delivery_address | pickup_date|
| -------- | -------------- |
| here | 08-03-2022 |
| here | 08-03-2022 |
| there| 09-03-2022 |
| there | 09-03-2022 |
example (incorrect, currently displaying):
| delivery_address | pickup_date|
| -------- | -------------- |
| here | 08-03-2022 |
| here | 08-03-2022 |
| here | 09-03-2022 |
| there| 09-03-2022 |
| there | 09-03-2022 |
Please advise thank you.
UPDATE
I have managed to solve my problem. Below is my solution:
dup_job = orders.filter(
orderpickup__pickup_date__range=(start_date, end_date)
).values(
'id_order',
'orderdelivery__delivery_address',
'orderpickup__pickup_date'
).annotate(
duplicated=Count('orderdelivery__delivery_address')
).filter(
duplicated__gt=1
)
UPDATE
I have managed to solve my problem. Below is my solution:
dup_job = orders.filter(
orderpickup__pickup_date__range=(start_date, end_date)
).values(
'id_order',
'orderdelivery__delivery_address',
'orderpickup__pickup_date'
).annotate(
duplicated=Count('orderdelivery__delivery_address')
).filter(
duplicated__gt=1
)

Issues with printing values from multiple arrays in python in the console

So I am trying to make a program that take in input for a flight, and stores it in arrays based on each type of input. Here are the arrays that I use to do this:
airline = []
flightNumbers = []
destination = []
gate = []
status = []
Here is the issue that I am having. After the user goes through and adds 1 flight, I want the program to print a flight status board in the console. For example if I enter:
"Delta", "Dl1480", "Atlanta", "E11", "Ontime"
"American", "AA367", "New York City", "H10", "Delayed"
"United", "UA3411", "Louisville, KY", "F25", "Cancelled"
this is what I want to see output by the program:
airline: | flight number: | destination: | gate: | status:
--------------------------------------------------------------------
Delta | DL1480 | Atlanta | E11 | Ontime
American | AA367 | New York City | H10 | Delayed
United | UA3417 | Louisville,KY | F25 | Cancelled
Here is what I tried to use to get this to print:
def showAll(self):
print("Airline | Flight Number | Destination | Gate | Status")
x = 0
while x < len(a.airline):
print(a.airline + [" | "] + a.flightNumbers + [" | "] + a.destination + [" | "] + a.gate + [" | "]+ a.status + ["\n"])
x += 1
but I get this as output if I enter 2 random entries:
Airline | Flight Number | Destination | Gate | Status
['delta', 'delta', ' | ', '001', '002', ' | ', 'Los angeles, ca', 'atlanta', ' | ', 'a1', 'a3', ' | ', 'ontime', 'ontime', '\n']
['delta', 'delta', ' | ', '001', '002', ' | ', 'Los angeles, ca', 'atlanta', ' | ', 'a1', 'a3', ' | ', 'ontime', 'ontime', '\n']
Can some suggest a way I can fix this, or a better way of going about this entirely? Here is the code for the entire program:
class FSB:
# arrays to store flight information
airline = []
flightNumbers = []
destination = []
gate = []
status = []
input = ""
def addFlight(self):
while input != "bye":
# get inputs
air = input("Enter an airline name >> ")
fn = input("Enter a flight number >> ")
dest = input("Enter a destination >> ")
g = input("Enter a gate number >> ")
stat = input("Enter a flight status >> ")
self.air = air
self.fn = fn
self.dest = dest
self.g = g
self.stat = stat
# add inputs to appropiate arrays
a.airline.append(self.air)
a.flightNumbers.append(self.fn)
a.destination.append(self.dest)
a.gate.append(self.g)
a.status.append(self.stat)
print("Data stored sucessfully.\n")
a.showAll()
def showAll(self):
print("Airline | Flight Number | Destination | Gate | Status")
x = 0
while x < len(a.airline):
print(a.airline + [" | "] + a.flightNumbers + [" | "] + a.destination + [" | "] + a.gate + [" | "]+ a.status + ["\n"])
x += 1
go = input("To add a new entry, enter 1.\nTo reprint list, enter 2.\nTo exit, enter 3.\n")
if go == "1":
a.addFlight()
elif go == "2":
for x in range(1,26):
print(" ")
a.showAll()
elif go == "3":
exit()
if __name__ == "__main__":
a = FSB()
a.addFlight()
You're trying to concatenate a string "|" to your list. Please try doing ["|"]instead.
I ended up iterating through each array manually, and this is what I got:
def showAll(self):
print("Airline\t\t\t" +"| Flight Number\t\t" +"| Destination\t\t" +"| Gate \t\t" +"| Status")
for x in range(len(a.airline)):
print("-------------------------------------------------------------------------------------------------------------------")
print(str(a.airline[x] + "\t\t") + str(a.flightNumbers[x] + "\t\t") + str(a.destination[x] + "\t\t\t\t") + str(a.gate[x] + "\t\t") + str(a.status[x]))
Thank you to everyone who suggested an answer, I appreciate it!

pyparsing nested structure not working as expected

I'm trying to parse a simple JSON-like structure into python dics and then turn it into a proper JSON structure. The block is as follows:
###################################################
# HEADER TEXT
# HEADER TEXT
###################################################
NAME => {
NAME => VALUE,
NAME => VALUE,
NAME => VALUE,
NAME => {
NAME => {
NAME => VALUE, NAME => VALUE, NAME => VALUE,
},
} # comment
}, # more comments
and repeating. Rules:
NAME = alphanums and _
VALUE = decimal(6) | hex (0xA) | list of hex ([0x1,0x2]) | text in brackets([A]) | string("A")
I set up the following grammar:
cfgName = Word(alphanums+"_")
cfgString = dblQuotedString().setParseAction(removeQuotes)
cfgNumber = Word("0123456789ABCDEFx")
LBRACK, RBRACK, LBRACE, RBRACE = map(Suppress, "[]{}")
EQUAL = Literal('=>').suppress()
cfgObject = Forward()
cfgValue = Forward()
cfgElements = delimitedList(cfgValue)
cfgArray = Group(LBRACK + Optional(cfgElements, []) + RBRACK)
cfgValue << (cfgString | cfgNumber | cfgArray | cfgName | Group(cfgObject))
memberDef = Group(cfgName + EQUAL + cfgValue)
cfgMembers = delimitedList(memberDef)
cfgObject << Dict(LBRACE + Optional(cfgMembers) + RBRACE)
cfgComment = pythonStyleComment
cfgObject.ignore(cfgComment)
EDIT: I've managed to isolate the problem. Proper JSON is
{member,member,member}
however my structure is:
{member,member,member,}
the last element in every nested structure is comma separated and I don't know how to account for that in the grammar.

generated code is not indent

I am modifying the oil file using python script. I have written EBNF grammar to convert oil file to AST using Grako. And generate oil file back from AST using codegen but the Oil file is not indent (generate in one line).
Sample Oil file:
CPU dummy
{
OS StdOS
{
SCALABILITYCLASS = SC1;
STATUS = EXTENDED;
};
};
Generated Oil:
CPUdummy{OSStdOS{SCALABILITYCLASS=SC1;STATUS=EXTENDED;};};
EBNF grammer:
file = [{Comments_option}] OIL_version Includes [implementation_definition] application_definition {object_definition_list};
Includes
= "#include" include_name ;
include_name
= ?/[!-_A-Za-z0-9]+/? ;
OIL_version
= "OIL_VERSION" "=" version description ";" ;
version = '"' ver '"';
implementation_definition
= "IMPLEMENTATION" name "{" implementation_spec_list "}" description ";";
implementation_spec_list
= [implementation_spec] ;
implementation_spec
= object "{" implementation_def "}" description ";";
object = "OS"
"TASK"
"COUNTER"
"ALARM"
"RESOURCE"
"EVENT"
"ISR"
"MESSAGE"
"COM"
"NM"
"APPMODE"
"IPDU"
"APPLICATION";
implementation_list
= [implementation_def]
| [implementation_list implementation_def] ;
implementation_def
= impl_attr_def
| impl_ref_def;
impl_attr_def
= "UINT32" auto_specifier number_range attribute_name multiple_specifier default_number description ";"
| ( "INT32" | "UINT64" | "INT64" ) auto_specifier number_range attribute_name multiple_specifier default_number description ";"
| "FLOAT" auto_specifier float_range attribute_name multiple_specifier default_float description ";"
| "ENUM" auto_specifier enumeration attribute_name multiple_specifier default_name description ";"
| "STRING" auto_specifier attribute_name multiple_specifier default_string description ";"
| "BOOLEAN" auto_specifier bool_values attribute_name multiple_specifier default_bool description ";" ;
impl_parameter_list
= [( "{" {implementation_def} [implementation_def] "}" )] ;
auto_specifier
= ["WITH_AUTO"];
number_range
= [( "[" ( number ".." | ( number ) ) number "]" )];
number_list
= number
| number_list "," number ;
default_number
= [( "=" ( number | "NO_DEFAULT" | "AUTO" ) )];
description
= [( ":" '"' comments '"' )] ;
float_range
= [( "[" float ".." float "]" )] ;
default_float
= [( "=" ( float | "NO_DEFAULT" | "AUTO" ) )] ;
enumeration
= "[" enumerator_list "]";
enumerator_list
= enumerator
| enumerator_list "," enumerator ;
enumerator
= name [impl_parameter_list] description;
bool_values
= [( "[" "TRUE" impl_parameter_list description "," "FALSE" impl_parameter_list description "]" )] ;
default_name
= [( "=" ( name | "NO_DEFAULT" | "AUTO" ) )] ;
default_string
= [( "=" ( string | "NO_DEFAULT" | "AUTO" ) )] ;
default_bool
= [( "=" ( boolean | "NO_DEFAULT" | "AUTO" ) )] ;
impl_ref_def
= object_ref_type reference_name multiple_specifier description ";";
object_ref_type
= "OS_TYPE"
| "TASK_TYPE"
| "COUNTER_TYPE"
| "ALARM_TYPE"
| "RESOURCE_TYPE"
| "EVENT_TYPE"
| "ISR_TYPE"
| "MESSAGE_TYPE"
| "COM_TYPE"
| "NM_TYPE"
| "APPMODE_TYPE"
| "IPDU_TYPE";
reference_name
= name
| object;
multiple_specifier
= [( "[" "]" )] ;
application_definition
= "CPU" name "{" [Includes] { ( parameter_list Comments_option ) } "}" description ";" ;
object_definition_list
= [object_definition];
Comment_list
= object_definition | parameter comments ;
object_definition
= object_name "{" { parameter_list Comments_option } "}" description ";" ;
object_name
= object name;
parameter_list
= [parameter];
parameter
= attribute_name "=" attribute_value [ "{" { ( parameter [Comments_option] ) } "}" ] description ";" ;
attribute_name
= name
| object;
attribute_value
= boolean
| float
| number
| string
| "AUTO"
| '"' string '"';
Comments_option
= ( Single_line Multi_line );
Single_line = {"//" comments};
Multi_line = {"/*#*" Comment_list "*#*/"};
name = ?/[-_A-Za-z0-9]+/?;
string = ?/[-_A-Za-z0-9_*, ]+/?;
ver = ?/[0-9.0-9]+/?;
comments = ?/[-_A-Za-z0-9 *#]+/? ;
boolean = "FALSE"
| "TRUE";
number = dec_number
| hex_number;
dec_number
= sign int_digits;
sign = [( "+" | "-" )] ;
int_digits
= zero_digit
| pos_digit
| pos_digit dec_digits ;
dec_digits
= {dec_digit} [dec_digit] ;
float = ver;
exponent = [( ( "e" | "E" ) sign dec_digits )] ;
zero_digit
= "0";
pos_digit
= "1"
| "2"
| "3"
| "4"
| "5"
| "6"
| "7"
| "8"
| "9";
dec_digit
= zero_digit
| pos_digit;
hex_number
= "0x" {hex_digit};
hex_digit
= "A"
| "B"
| "C"
| "D"
| "E"
| "F"
| "a"
| "b"
| "c"
| "d"
| "e"
| "f"
| "0"
| "1"
| "2"
| "3"
| "4"
| "5"
| "6"
| "7"
| "8"
| "9";
For indentation grako to be taken care or codegen. How to indent the generated code. Thanks.
import json
from grako.util import asjson
print(json.dumps(asjson(myast), indent=4))

Do I use integer or float?

This is the model in Google App Engine:
class Rep(db.Model):
mAUTHOR = db.UserProperty(auto_current_user=True)
mUNIQUE = db.StringProperty()
mCOUNT = db.IntegerProperty()
mDATE = db.DateTimeProperty(auto_now=True)
mDATE0 = db.DateTimeProperty(auto_now_add=True)
mWEIGHT = db.FloatProperty()
So, mCOUNT is integer and mWEIGHT is float. I calculate the age of the item like this:
age1 = datetime.datetime.now() - rep.mDATE0
age_hour = float(age1.seconds) / 3600
rep.mWEIGHT = float((rep.mCOUNT - 1) / (age_hour + 2)**1.5)
But when I try a query like this:
QUERY = Rep.all()
QUERY.filter("mAUTHOR =", user)
QUERY.order("-mWEIGHT")
RESULTS = QUERY.fetch(10)
for result in RESULTS:
self.response.out.write("mUNIQUE: <b>%s</b> | "
"mWEIGHT: %f | "
"mCOUNT: %s | <br />"
% (result.mUNIQUE,
result.mWEIGHT,
# line 103
result.mCOUNT,
))
I get a TypeError on line 103 which is
result.mCOUNT,
TypeError: a float is required
Why would mCOUNT be float? By the way, the error is raised only if the item is not in the datastore and it is written for the first time by the else clause of the if loop.
Can you help me use the correct type? Thanks for your help.
-----------------------------------------------------
EDIT
I just noticed that I had %f for string formatting for mWEIGHT and changing that to %s seems to solve the problem (but I don't know why. Is it because mWEIGHT=None?):
for result in RESULTS:
self.response.out.write("mUNIQUE: <b>%s</b> | "
# changing %f to %s appears to solve the problem.
"mWEIGHT: %f | "
"mCOUNT: %s | <br />"
% (result.mUNIQUE,
result.mWEIGHT if result.mWEIGHT is not None else 0.0,
result.mWEIGHT,
result.mCOUNT,
))
And here are some values:
mUNIQUE: A | mWEIGHT: 0.299954933969 | mCOUNT: 2 |
mUNIQUE: Z | mWEIGHT: 0.0 | mCOUNT: 1 | # With answer by TokenMacGuy
mUNIQUE: R | mWEIGHT: None | mCOUNT: 1 | # with %f changed to %s
mUNIQUE: P | mWEIGHT: None | mCOUNT: 1 | # with %f changed to %s
Any suggestions how I can add rep.mWEIGHT to the else clause?
------------------------------------------------------------
The entire code is below:
K = []
s = self.request.get('sentence')
K.append(s)
K = f2.remove_empty(K[0].split('\r\n'))
UNIQUES = f2.f2(K)
COUNTS = f2.lcount(K, UNIQUES)
C_RESULT = "no results yet"
for i in range(len(UNIQUES)):
C_QUERY = Rep.all()
C_QUERY.filter("mAUTHOR =", user)
C_QUERY.filter("mUNIQUE =", UNIQUES[i])
C_RESULT = C_QUERY.fetch(1)
if C_RESULT:
rep = C_RESULT[0]
rep.mCOUNT+=COUNTS[i]
age1 = datetime.datetime.now() - rep.mDATE0
age_hour = float(age1.seconds) / 3600
rep.mWEIGHT = float((rep.mCOUNT - 1) / (age_hour + 2)**1.5)
self.response.out.write("<b>rep.UNIQUE: %s</b>: <br />"
# "rep.mCOUNT: %s <br />"
"rep.mWEIGHT: %s <br />"
# "C_RESULT: %s <br />"
# "rep: %s <br />"
# "utc_tuple: %s <br />"
# "mDATE0_epoch: %s <br />"
"rep.mDATE0: %s "
"age_hour: %s <br />"
#
% (rep.mUNIQUE,
# rep.mCOUNT,
rep.mWEIGHT,
# C_RESULT,
# rep,
# utc_tuple,
# mDATE0_epoch,
rep.mDATE0,
age_hour,
))
rep.put()
else:
rep = Rep()
rep.mCOUNT = COUNTS[i]
rep.mUNIQUE = UNIQUES[i]
rep.put()
self.response.out.write("<b>rep.UNIQUE: %s</b>: |"
"rep.mCOUNT: %s: <br />"
% (rep.mUNIQUE,
rep.mCOUNT,))
QUERY = Rep.all()
QUERY.filter("mAUTHOR =", user)
QUERY.order("-mWEIGHT")
RESULTS = QUERY.fetch(10)
for result in RESULTS:
self.response.out.write("mUNIQUE: <b>%s</b> | "
"mWEIGHT: %f | "
"mCOUNT: %s | <br />"
% (result.mUNIQUE,
result.mWEIGHT,
result.mCOUNT,
))
It looks like you are occasionally not setting mWEIGHT. How about changing
for result in RESULTS:
self.response.out.write("mUNIQUE: <b>%s</b> | "
"mWEIGHT: %f | "
"mCOUNT: %s | <br />"
% (result.mUNIQUE,
result.mWEIGHT,
result.mCOUNT,
))
to
for result in RESULTS:
self.response.out.write("mUNIQUE: <b>%s</b> | "
"mWEIGHT: %f | "
"mCOUNT: %s | <br />"
% (result.mUNIQUE,
result.mWEIGHT if result.mWEIGHT is not None else 0.0,
result.mCOUNT,
))

Categories