import urllib2
from bs4 import BeautifulSoup
import requests
import os
import sys
sys.path.append("../../pypoj")

from requests.exceptions import HTTPError
from datainitializer.AppPipeline import AppPipeline
from datainitializer.AppItem import AppItem
from config.constant import Values

parsed_apks = set(line.strip() for line in open(Values.drebin_179f_1500_appsinfo_txt_path))
db_pipeline = AppPipeline(Values.drebin_179f_1500_appsinfo_path)
db_pipeline.initialize()

i=0
for apk_info in parsed_apks:
	infos = apk_info.split('---')
	apppath = infos[0]
	pkgname = infos[1]
	mainaty = infos[2]
	permissions = infos[3]
	if permissions:
		permissions.replace('++','\n')
	else:
		permissions = None

	apkname = apppath.split('/')[-1][:-4]
	app_item = AppItem(apppath,apkname,pkgname,mainaty,permissions,None,None,None)
	db_pipeline.insert_into_DB(app_item)

	print i
	i+=1
db_pipeline.finalize()
