为引用的猫鼬模型编写种子脚本的最优雅方法是什么?我更喜欢self.a
语法。我做了一个'''
customer_class.py: create a class that can a person name, address, age and phone number
and make a program that can make three instances of the class one to hold
personal information and two more to hold a friends information
next make a subclass that display the customer number and if they wish to be on the
mailing list
By: Javon Jamison
3/17/2020
'''
class Person(object):
def __init__(self, name, address, age, phone_number):
self.name = name
self.address = address
self.age = age
self.phone = phone_number
def get_name(self):
return self.name
def get_address(self):
return self.address
def get_age(self):
return self.age
def get_phone(self):
return self.phone
def __str__(self):
return "Name: " + self.name + "\n" + "Address: " + self.address \
+ "\n" + "age: " + self.age + "\n" + "Number: " + self.phone
#person1 = Person('Javon', '123 road', "18", "123-456-7890")
#person2 = Person('Wll', '124 road', "19", "122-455-7893")
#person3 = Person('Bhari', '125 road', "20", "111-222-4444")
#print(person1, "\n", person2, "\n", person3)
class Customer(Person):
""" subclass of Person"""
def __init__(self, name, address, age, phone_number, decision):
super().__init__(name, address, age, phone_number)
self.number = phone_number
self.decision = decision
def get_number(self, phone_number):
""" get customer number"""
return self.number == phone_number
def set_decision(self, decision):
""" get the customer decision"""
return self.decision == decision
def __bool__(self):
""" determine if they want to be on the list"""
if self.decision == "y":
return True
elif self.decision == "n":
return False
def __str__(self):
""" display the number and if they want to be on mailing list"""
return self.number
cust1 = Customer('Javon', '123 road', "18", "123-456-7890", "n")
print(cust1)
print(bool(cust1.decision))
工作示例,但我相信它可以写得更优雅。例如,我有一些任意逻辑,用9条消息引用3个用户,这不好。我希望看到一个更好的解决方案并从中学习。
用户模型
const pup = require('puppeteer');
(async () => {
console.log('launch browser');
const browser = await pup.launch({headless: false});
//SELECTORS:
var userInputSel = '#username';
var passInputSel = '#password';
var loginBtnSel = '#auth_login_ws_header > form > button';
var myUser = "Nastygamenation"; //PUT YOUR USERNAME HERE!!!
var myPass = "test"; //PUT YOUR PASSWORD HERE!!!
console.log('new page');
const page = await browser.newPage();
console.log('goto');
await page.setViewport({ width: 1920, height: 1080 });
await page.goto('https://server.nitrado.net/usa/rent-gameserver', { waitUntil: "networkidle2", timeout: 60000 });
await page.waitFor(5000);
console.log('extract login iframe');
var iframes = await page.frames();
var loginFrame = iframes.find(f => f.url().indexOf("oauth.nitrado.net") > -1);
await page.waitFor(5000);
console.log('evaluate iframe');
/*await loginFrame.evaluate(() => {
document.getElementById('username').value = 'Nastygamenation';
document.getElementById('password').value = 'test';
});*/
await page.waitFor(7000);
console.log('Logged in > going to logs');
await page.waitForSelector(userInputSel);
await page.type(userInputSel, myUser);
await page.waitForSelector(passInputSel);
await page.type(passInputSel, myPass);
await page.waitForSelector(loginBtnSel);
await page.click(loginBtnSel);
await page.waitFor(300000);
console.log('done');
await browser.close();
})()
消息模型
throw err;
^
Error: Cannot find module 'C:\Users\logan\Desktop\GamerBot\test.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
at Function.Module._load (internal/modules/cjs/loader.js:864:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}```
种子功能
async/await