Last active
August 29, 2015 14:00
-
-
Save gunesmes/3fdddf2dbd230661bbec to your computer and use it in GitHub Desktop.
From Java, you can call Python function which creates a new e-mail for testing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Created on Apr 8, 2014 | |
@author: gunesmes@yahoo.com | |
''' | |
# -*- coding: utf8 -*- | |
import datetime, os | |
#import config | |
os.chdir("D:/workspace/projectname/test-output") | |
class TestData(): | |
def createEmail(self): | |
emailBase = "username" | |
emailSup = "gmail.com" | |
# read the text file as a list of lines | |
# find the last line, change to a file you have | |
data = open('numberRun.txt', "r") | |
lineList = data.readlines() | |
now = datetime.datetime.now() | |
#first time running, empty list | |
if len(lineList) == 0: | |
lastLineList = ('0' + ',' + emailBase + ',' + str(now.strftime("%Y-%m-%d %H:%M")) + ',' + 'False') | |
else: | |
lastLineList = lineList[len(lineList)-1] | |
(lastUsedNumber, lastUsedEmail, Date, isRegistered) = lastLineList.split(",") | |
lastUsedNumber2 = lastUsedNumber.replace("(", "") | |
newEmail = (emailBase + '+' + str(int(lastUsedNumber2) + 1) + '@' + emailSup) | |
data.close() | |
data = open('./numberRun.txt', "a") | |
now = datetime.datetime.now() | |
newEmailFull = int(lastUsedNumber2)+1, str(newEmail), str(now.strftime("%Y-%m-%d %H:%M")), "YES" | |
data.write(str(newEmailFull)) | |
data.write("\n") | |
data.close() | |
#print newEmailFull | |
return newEmail | |
def get_number_of_run(self): | |
# read the text file as a list of lines | |
# find the last line, change to a file you have | |
data = open('numberRun.txt', "r") | |
lineList = data.readlines() | |
lastLineList = lineList[len(lineList)-1] | |
(lastUsedNumber, lastUsedEmail, Date, isRegistered) = lastLineList.split(",") | |
lastUsedNumber2 = lastUsedNumber.replace("(", "") | |
data.close() | |
return lastUsedNumber2 | |
m = TestData() | |
result = m.createEmail() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.python.antlr.ast.Str; | |
import org.python.core.PyObject; | |
import org.python.util.PythonInterpreter; | |
public class ProjectName{ | |
public String createEmail() { | |
PythonInterpreter python = new PythonInterpreter(); | |
// full path of the python file | |
python.execfile("D:\\workspace\\pojectname\\src\\com\\base\\test_data.py"); | |
PyObject epost = python.get("result"); | |
String eposta = epost.toString(); | |
System.out.printf(" * New e-mail is created: %s\n", eposta); | |
return eposta; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment