forked from dem972/Mosyle_2snipe
-
Notifications
You must be signed in to change notification settings - Fork 4
/
appleInfo.py
77 lines (64 loc) · 2.84 KB
/
appleInfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#this file can be run to update your Snipe-IT models without interacting with Mosyle.
import base64
from tracemalloc import stop
import requests
import json
import datetime
import configparser
import colorama
from sys import exit
from mosyle import Mosyle
from snipe import Snipe
from colorama import Fore
from colorama import Style
from operator import mod
modelNumber = "iPad11,2";
# Converts datetim/e to timestamp for Mosyle
ts = datetime.datetime.now().timestamp() - 200
# Set some Variables from the settings.conf:
config = configparser.ConfigParser()
config.read('settings.ini')
# This is the address, cname, or FQDN for your snipe-it instance.
snipe_url = config['snipe-it']['url']
apiKey = config['snipe-it']['apiKey']
defaultStatus = config['snipe-it']['defaultStatus']
apple_manufacturer_id = config['snipe-it']['manufacturer_id']
macos_category_id = config['snipe-it']['macos_category_id']
ios_category_id = config['snipe-it']['ios_category_id']
tvos_category_id = config['snipe-it']['tvos_category_id']
macos_fieldset_id = config['snipe-it']['macos_fieldset_id']
ios_fieldset_id = config['snipe-it']['ios_fieldset_id']
tvos_fieldset_id = config['snipe-it']['tvos_fieldset_id']
deviceTypes = config['mosyle']['deviceTypes'].split(',')
snipe_rate_limit = int(config['snipe-it']['rate_limit'])
apple_image_check = config['snipe-it'].getboolean('apple_image_check')
#setup the snipe-it api
snipe = Snipe(apiKey,snipe_url,apple_manufacturer_id,macos_category_id,ios_category_id,tvos_category_id,snipe_rate_limit, macos_fieldset_id, ios_fieldset_id, tvos_fieldset_id,apple_image_check)
#get all models
models = snipe.listAllModels().json()
print(models);
#loop through each model
for model in models['rows']:
#is the model's manufacturer Apple?
print('Processing model: ' + str(model['id']), model["model_number"])
print("Is the model's manufacturer Apple?", "checking manufacture id " + str(model['manufacturer']['id']) +" against known apple manufacturer id: "+ str(apple_manufacturer_id))
if int(model['manufacturer']['id']) == int(apple_manufacturer_id):
#yes!
print(Fore.GREEN, "Yes! Checking for photo!", Style.RESET_ALL);
#Does it need a picture?
if model['image'] == None:
print("No photo. Dowloading photos")
imageResponse = snipe.getImageForModel(model["model_number"]);
if imageResponse != False:
print("Photo Downloaded")
snipe.setImageForModel(model["id"],imageResponse.content)
payload = {
"image": imageResponse
}
snipe.updateModel(str(model['id']), payload)
else:
print("no photo found, moving on")
else:
print("picture already set. Skipping")
else:
print(Fore.YELLOW,'model is not apple. Skip.',Style.RESET_ALL)