def generate_hotp(secret, counter=4):
 msg = struct.pack('>Q', counter)
 digest = hmac.new(to_bytes(secret), msg, hashlib.sha1).digest()
 ob = digest[19]
 if PY2:
  ob = ord(ob)
 pos = (ob & 15)
 base = (struct.unpack('>I', digest[pos:(pos + 4)])[0] & 2147483647)
 token = (base % 1000000)
 return token

def generate_hotp ( secret , counter = 4 ) : msg = struct . pack ( '>Q' , counter ) digest = hmac . new ( to_bytes ( secret ) , msg , hashlib . sha1 ) . digest ( ) ob = digest [ 19 ] if PY2 : ob = ord ( ob ) pos = ( ob & 15 ) base = ( struct . unpack ( '>I' , digest [ pos : ( pos + 4 ) ] ) [ 0 ] & 2147483647 ) token = ( base % 1000000 ) return token
generate a hotp code .