ラベル 覚え書き の投稿を表示しています。 すべての投稿を表示
ラベル 覚え書き の投稿を表示しています。 すべての投稿を表示

2011年6月29日水曜日

[Wordpress]カテゴリをcsvfileから一気に登録する自作関数を作った[PHP]

csvfileの中身は

-----

col1,col2

CategoriSlag,CategoriName

カテゴリのスラッグ,カテゴリの名前

----

的なものにする。

$csv_path = "http://hogehoge.domein/foo.csv";//

function registerCategies($csv_path)
{
	if( $handle = fopen( $csv_path, 'r' ) ){
		$term_id = 3;//1は未分類,2はブログロールの場合。!!それ以外の場合は修正が必要!!
	        while( ( $lines = fgetcsv( $handle ) ) !== FALSE ){
				$name=$lines[1];//カテゴリの名前
				$category_description = $lines[1]."のカテゴリ";//ここはご自由にカスタマイズしてね。
				$slug=$lines[0];//カテゴリのスラッグ
				$term_group=0;//カテゴリのグループ
				
//以下はwpのデータベースへの登録のメソッド
$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES (%d, %s, %s, %d)", $term_id, $name, $slug, $term_group) );
$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id,taxonomy,description) VALUES (%d, %s, %s)", $term_id, "category", $description) );
				$term_id++;
	        }
	}

}

これで出来てるはず(。◕ ∀ ◕。)

2011年6月23日木曜日

気になること、やりたい事2011-06-23時点

特に意味はない覚え書きです。。。。
  • 顔認証のプログラム組みたいのでopencvについての勉強
  • Voip,p2pについての勉強
  • Blenderについての勉強
  • iTunes connnect でappの審査通過後そのことをブログに書く本日10日目、、、遅すぎる。。ダメなら早くリジェクトしてくれ〜〜><

2011年6月16日木曜日

Pythonで htmlを逆escape(unescape)する

日本語のちゃんとした言葉がわからなくて申し訳ないのですが

 

'&amp;''&lt;',  '&gt;'

などを

&,<,>に変更する方法です。

 

import xml.sax.saxutils

xml.sax.saxutils.unescape('&amp;,&lt;,&gt;')


これでunescape出来ます。

 

 

 

ちなみに普通のescapeは

import cgi

cgi.escape(&amp;,&lt;,&gt;')

 

で出来ます。

2011年5月15日日曜日

iPhone appのアイコンの規定

PNG形式 デフォルトのファイル名は「Icon.png」(「Info.plist」ファイルで変更可) アイコンサイズは57px×57px(iPadは、72px×72px、iPhone 4は、114px×114px) 角の丸みと光沢のエフェクトはシステムが自動的に付加(Info.plistファイルで変更可) アプリケーションのトップディレクトリに配置

2011年5月11日水曜日

base64の使い方 --python--

'''base64の使い方'''

part = base64.b64encode('pass')

print(part)#cGFzcw==
print(base64.b64decode(part)) #pass

'''URLのパラメータとして使う場合は下記'''
part = base64.urlsafe_b64encode('pass')

print(part)#cGFzcw==
print(base64.urlsafe_b64decode(part))#cGFzcw==

md5,shaの使い方 --python--

'''md5の使い方'''

m = md5.new('pass-word')

print (m) #
print (m.hexdigest()) #ed0eacb4e34e50c1c53f9698600d4b86

import urllib

'''多分クオートしないとエラーになる...'''
try:
	print m.digest()
except UnicodeDecodeError:
	print u'UnicodeDecodeErrorなのだ'


'''URLのパラメータとして使用する場合はクオートする必要がある'''
quoted =''.join([urllib.quote_plus(x) for x in m.digest()])

print quoted #%ED%0E%AC%B4%E3NP%C1%C5%3F%96%98%60%0DK%86
'''shaの使い方'''

m = sha.new('pass-word')

print (m) #
print (m.hexdigest()) #ed0eacb4e34e50c1c53f9698600d4b86

import urllib

'''多分クオートしないとエラーになる...'''
try:
	print m.digest()
except UnicodeDecodeError:
	print u'UnicodeDecodeErrorなのだ'


'''URLのパラメータとして使用する場合はクオートする必要がある'''
quoted =''.join([urllib.quote_plus(x) for x in m.digest()])

print quoted #%ED%0E%AC%B4%E3NP%C1%C5%3F%96%98%60%0DK%86

pickleの使い方--python--

'''pickleの使い方'''

'適当なオブジェクトを用意する'
o = [1,2,3,(1,2,3),{1,2,3,4,(1,2)}]

print o #[1, 2, 3, (1, 2, 3), set([(1, 2), 1, 2, 3, 4])]


"""書き込みモードで開く"""
opened = open('test.dump','w')

'''pickle化'''
pickle.dump(o,opened)		
'''同ディレクトリにtest.dumpとして保存されている'''

opened.close()

'''dumpファイルを開く'''
opened2 = open('test.dump')

o2 = pickle.load(opened2) 

print o2 #[1, 2, 3, (1, 2, 3), set([(1, 2), 1, 2, 3, 4])]
'''ちゃんとオブジェクトとして再現できる'''
print o2[3][2] #3

o2.append({'hoge':'foo'})

print o2 #[1, 2, 3, (1, 2, 3), set([(1, 2), 1, 2, 3, 4]), {'hoge': 'foo'}]
opened2.close()

opened3 = open('test.dump','w')
	
'再度保存するときはdump'
pickle.dump(o2,opened3)

shelveの使い方--python--

import shelve


def main():
	
	"""shelveの使い方"""
	
	'''shelvetestという名前のファイルを保存'''
	d = shelve.open("shelvetest",writeback=True)
	
	'辞書と同じ使い方でデーターを挿入'
	d.update({"one":"1","tow":"2"})
	
	print(d) #{'tow': '2', 'one': '1'}
	
	'''closeした時点でファイルとして保存される'''
	d.close()
	print "-"*30
	
	'ファイル名を指定して開く'
	d2 = shelve.open("shelvetest")
	
	print(d2) #{'tow': '2', 'one': '1'}

	d2.close()
	
if __name__ == '__main__':
	main()


xcode4でpythonを使う

参考したURLが英語だったので日本語に訳す。

  1. Xcode4を開く
  2. メニューバー→File→New→New Projectと選ぶ
  3. Mac OSXの範囲にあるOtherを選ぶ
  4. External Build Systemを選んでNext
  5. 任意のProduct nameを入力する
  6. Build Toolに/usr/local/bin/python3、/usr/bin/python等とpythonの位置を指定してNext
  7. 任意の保存場所を指定してCreate

 

 

  1. メニューバー→File→New→New Fileと選ぶ
  2. Mac OSXの範囲にあるOtherを選ぶ
  3. Emptyを選んでNext
  4. 任意の保存するディレクトリをえらんで.pyのpython形式でファイル名を指定してSave

 

  1. メニューバー→Product→Edit Schemeと選ぶ
  2. 左側にあるRunという項目をクリックする
  3. infoタブにあるExecutableをOtherに変更
  4. ⇧⌘Gと押すと隠しフォルダを指定して移動できるのでExternal Build Systemとして指定したファイルを指定(この方法は今回初めて知った!!便利>o<)
  5. Debuggerの項目はNoneに変更
  6. Base Expansions Onの項目に作成したproduct nameを指定
  7. Arguments Passed On Launchの項目の下にある+ボタンをクリックして・・・

ここからわからん。。。。w

一度保留して、hello worldを試してみたけど、xcodeがすぐ落ちる。。。

だれか、教えて〜〜〜><

  1. Click the "+" icon under "Arguments Passed On Launch". You may have to expand that section by clicking on the triangle pointing to the right.
  2. Type in "$(SOURCE_ROOT)/" without the quotes and then the name of the Python file you want to test. Remember, the Python program must be in the project folder. Otherwise, you will have to type out the full path here.
  3. Click "OK".
  4. Start coding.

原文:http://stackoverflow.com/questions/5276967/python-in-xcode-4

2011年5月2日月曜日

Python覚え書き

file = open('index.html') html = file.read()

↓短縮

html = open("index.html").read()

2011年4月26日火曜日

画像とかのクリックをかんたんに無効にするCSS

簡単な方法なのに使いたい時には忘れてしまい、なおかつ検索してもなかなか出てこないのでメモしてみる。 pointer-events: none; これでクリック無効出来ます。