piątek, 1 marca 2019

Robot framerowk

INSTALLATION

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#installation-instructions







Python sandbox

VARIABLES
x = 1 #int
y = 2.5 #float
name = 'Bran' #string
is_cool = True #bool

#multiple assigment
x, y, name, is_cool = (1, 2.5, 'Brad', True)

print(x, y, name, is_cool)

#basic math
a = x+y

#check type
print(type(is_cool))

#casting
x = str(x)
y = int(y)
z = float(y)

#check type
print(type(x))
print(y)

VALIDATORS
# Example of a custom module to be imported

import re


def validate_email(email):
if len(email) > 7:
return bool(re.match("^.+@(\[?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,3}|[0-9]{1,3})(]?)$", email))

TUPLES
# A Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
#Sample tuple

fruit_tuple = ('Apple', 'Orange','Mango')

print(fruit_tuple)

print(fruit_tuple[1])


JSON
# JSON is commonly used with data APIS. Here how we can parse JSON into a Python dictionary
import json

userJson = '{"first_name": "John", "last_name": "Doe", "age": 24}'

#parse to dictionary
user = json.loads(userJson)

print(user)
print(user['first_name'])

car = {'make': 'Ford', 'model': 'mustang', 'year': 1970}

carJSON = json.dumps(car)

print(carJSON)

MODULES
# A module is basically a file containing a set of functions to include in your application. There are core python modules, modules you can install using the pip package manager (including Django) as well as custom modules

import datetime
import time
from time import time

import camelcase
import validator

today = datetime.date.today()
print(today)

timestamp = time()
print(timestamp)

camel = camelcase.CamelCase()

text = 'hellow world'

print(camel.hump(text))

email = 'test@test.com'
if validator.validate_email(email):
print('Email is valid')
else:

LOOPS
# A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).

people = ['John', 'Karen', 'Will', 'Janet']

#simple for loop
for person in people:
print('Current person ', person)

#breakout
for person in people:
print('Current person ', person)
if person == 'Karen':
break

#continue
for person in people:
print('Current person ', person)
if person == 'Karen':
continue

#range
for i in range(len(people)):
print('Current person ', people[i])

# While loops execute a set of statements as long as a condition is true.
count = 0
while count <= 10:
print(count)
count +=1

FUNCTIONS
# creatw function
def sayHello(name):
print('hello ' + name)

sayHello('Sam')

def getSum(num1, num2):
total = num1 + num2
return total

numSum = getSum(1, 2)
print(numSum)

FILES
# Python has functions for creating, reading, updating, and deleting files.

#open a file
myFile = open('file.txt', 'w')

print('Name: ', myFile.name)
print('Is Closed: ', myFile.closed)
print('Mode: ', myFile.mode)

#file write
myFile.write('I love python')
myFile.close()

#append to file
myFile = open('file.txt', 'a')
myFile.write(' I also love ptyhon')
myFile.close()

#read from file
myFile = open('file.txt', 'r+')
text = myFile.read(100)
print(text)

DICTIONARIES
# A Dictionary is a collection which is unordered, changeable and indexed. No duplicate members.

#simple dict
person = {
'first_name': 'John',
'last_name': 'Doe',
'age': 30
}

print(person)

#person = dict(first_name='John', last_name='Doe', age=30)

print(person['first_name'])

#add values
person['phone'] = '555-55-55'
print(person)

# get keys
print(person.items())

# msake a copy
person2 = person.copy()
print(person2)

#remove
del(person['age'])
print(person)
print(person2)

CLASSES
# A class is like a blueprint for creating objects. An object has properties and methods(functions) associated with it. Almost everything in Python is an object

class User:
#constructor
def __init__(self, name, email, age):
self.name = name
self.email = email
self.age = age

def greeting(self):
return f'my name is {self.name} and I am {self.age}'

def has_birthday(self):
self.age +=1

#init user object
brad = User('Brad Teresky', 'test@test.pl', 23)
janet = User('Janet', 'test@janet.pl', 34)

#edit property
brad.age = 43

print(brad.name, brad.age)

janet.has_birthday()

#call method
print(janet.greeting())

poniedziałek, 31 sierpnia 2015

PHP registration form with email confirmation

In this tutorial I will focus on registration from with email confirmation.

  1. First we have to create tabel in MySQL with user data and with field "auth_code". To this field script will insert unique number and send this number to email.
  2. Create vriable with unique id number $kod = uniqid();
  3. Modify SQL insert statement to insert this number to tabel with users mysql_query("INSERT INTO uzytkownicy (..., kod_aktywacyjny) VALUES (..., $kod)");
  4. Using mail function send mail with link and this number to email
  5. After click on link the next script has to get this number from url and compare it with number from database and show message that account was activated