python 美元子层

subLayer.py
# -*- coding: utf-8 -*-
"""
subLayerで合成する
"""

# %%

from pxr import Usd, UsdGeom, Sdf, Gf

USD_PATH_ROOT = "I:/usd_test"
kitchenSetRoot = USD_PATH_ROOT + "/Kitchen_set/assets/"

stage = Usd.Stage.CreateInMemory()
rootLayer = stage.GetRootLayer()

rootLayer.subLayerPaths = [kitchenSetRoot + "/Book/Book.usd", kitchenSetRoot + "/Ball/Ball.usd"]

bookPath = Sdf.Path("/Book")
bookPrim = stage.GetPrimAtPath(bookPath)
UsdGeom.XformCommonAPI(bookPrim).SetTranslate((0, 50, 0))


# %%
print(stage.GetRootLayer().ExportToString())
# %%
stage.GetRootLayer().Export(USD_PATH_ROOT + "/subLayerTest.usda")
# %%

python sqlserver连接python

sqlserverconnection.py
import pyodbc
server = 'localhost'
database = 'databasename'
username = 'user'
password = 'password'

#Connection String
connection = pyodbc.connect('DRIVER={SQL Server Native Client 11.0};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = connection.cursor()

#Sample select query
cursor.execute("SELECT * from audit_types;")
row = cursor.fetchone()
while row:
    print(row[1])
    row = cursor.fetchone()

python Unittests任务3

test_file_storage.py
@unittest.skipIf(modesl.storage_t == 'db', "not testing file storage")
    def test_get(self):
        """Test that get method returns the correct object or None"""
        c = City()
        self.assertEqual(c, get("City", c.id))

        """Test that get method fails if None in place of class is passed"""
        self.assertEqual(None, get(None, c.id))

        """Test that get method fails if incorrect id is passed"""
        self.assertEqual(None, get("City", "54332"))

        """Test that get method fails if "NULL" id is passed"""
        self.assertEqual(None, get("City", "NULL"))

python ScrapyNotes2019.py

ScrapyNotes2019.py
# first step

# scrapy startproject tutorial
# cd tutorial
# scrapy genspider example example.com


----------------------------------------------------------------------------------
 
###proxy https://github.com/aivarsk/scrapy-proxies
#pip install scrapy_proxies
 
#settings.py
# Retry many times since proxies often fail
RETRY_TIMES = 10
# Retry on most error codes since proxies fail for different reasons
RETRY_HTTP_CODES = [500, 503, 504, 400, 403, 404, 408]
 
DOWNLOADER_MIDDLEWARES = {
    'scrapy.downloadermiddlewares.retry.RetryMiddleware': 90,
    'scrapy_proxies.RandomProxy': 100,
    'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 110,
}
 
# Proxy list containing entries like
# http://host1:port
# http://username:password@host2:port
# http://host3:port
# ...
PROXY_LIST = '/path/to/proxy/list.txt'
 
# Proxy mode
# 0 = Every requests have different proxy
# 1 = Take only one proxy from the list and assign it to every requests
# 2 = Put a custom proxy to use in the settings
PROXY_MODE = 0
 
# If proxy mode is 2 uncomment this sentence :
#CUSTOM_PROXY = "http://host1:port"
#----------------------------------------------------------------------------------

#----------------------------------------------------------------------------------
 
#fake_useraget
# https://github.com/alecxe/scrapy-fake-useragent
 
$ pip install scrapy-fake-useragent
 
DOWNLOADER_MIDDLEWARES = {
    'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': None,
    'scrapy_fake_useragent.middleware.RandomUserAgentMiddleware': 400,
}
 
 
#----------------------------------------------------------------------------------

python 正则表达式

ipr all seize
#extract value from text column into new column with regex pattern
df['new_col'] = df['string_col'].str.extract((r'(DV.+\d*)MSRP'), expand=True)

python 犀牛脚本

RhinoScripts
#--- Make Layers --- 
#https://discourse.mcneel.com/t/creating-sublayers-with-python/55948/2
#https://developer.rhino3d.com/samples/rhinocommon/add-layer/
import rhinoscriptsyntax as rs

def TestAddSubLayers():
    parent_layer="MainLayer"
    if not rs.IsLayer(parent_layer): rs.AddLayer(parent_layer)
    sublayernames = ["Layer1", "Layer2", "Layer3"]
    Colors = [(255,0,0), (0,255,0), (0,255,255)]
    for i in range(len(sublayernames)):
        # Color is also directly specifiable
        rs.AddLayer(sublayernames[i],color=Colors[i],parent=parent_layer)
TestAddSubLayers()
#--- Make Layers End ---

python 任务8.城市

cities.py
""" Create cities.py inside views in v1 
  Use to_dict() method to serialize object into valid JSON """

@app.route('/api/v1/states/<state_id>/cities')
# GET - Retrieves list of all City objects of a State
# if not state_id raise 404 error
# POST - Creates a new city, returns City object with status code 201
# - if state_id not linked to State object raise 404
# - if HTTP body request not valid JSON raise 400 error message "Not a JSON"
# - if dictionary doesn't contain key name raise 400 error message "Missing name"
# use request.get_json to transform HTTP body to dictionary

@app.route('api/v1/cities/<city_id>')
# GET - Retrieve a City object or 404 error
# DELETE - if city_id not linked to City object, raise 404 error
# - else return empty dictionary with status code 200
# PUT - Update State object with all key, val pairs of dictionary
# and return City object with status code 200
# - if HTTP body request not valid JSON raise 400 error message "Not a JSON"
# - if city_id not linked to City object, raise 404 error
# use request.get_json to transform HTTP body to dictionary
# ignore keys id, created_at, updated_at
__init__.py
""" Update __init__.py inside views in v1 """
# Import new cities.py file

python 任务13. HTTP访问控制(CORS)

app.py
""" Update app.py inside v1 in api
Note: you will need to install the module:
  pip3 install flask_cors """

# Create a CORS instance allowing /* for 0.0.0.0

python 任务7.国家

states.py
""" Create states.py inside views folder in v1 
  Use to_dict() method to serialize object into valid JSON """

@app.route('/api/v1/states')
# GET - Retrieve list of all state objects
# POST - Create a State object and returns new State with status code 201
# - if dictionary doesn't contain key name, raise 400 error message "Missing name"
# - if HTTP body request not valid JSON raise 400 error message "Not a JSON"
# use request.get_json to transform HTTP body to dictionary

@app.route('api/v1/states/<state_id>')
# GET - Retrieve a State object or 404 error
# DELETE - if state_id not linked to State object, raise 404 error
# - else return empty dictionary with status code 200
# PUT - Update State object with all key, val pairs of dictionary
# and return State object with status code 200
# - if state_id not linked to State object, raise 404 error
# - if HTTP body request not valid JSON raise 400 error message "Not a JSON"
# use request.get_json to transform HTTP body to dictionary
# ignore keys id, created_at, updated_at
__init__.py
""" Update __init__.py inside views in v1 """

// Import new states.py file

python 任务6.未找到

app.py
""" Update app.py """

# Create handler for 404 errors that returns a JSON-formatted 404 status code response
# Content of response is "error": "Not found"